I did a google search for some binary tree representations in Scheme, and most seemed to use #f to represent the base case, or that you are at the leaf of a node. Is it bad to do something like this instead? (struct tree (val left right) #:transparent)
(struct leaf (char freq) #:transparent)
and have the leaves which will be the left/right of some trees as leaf structs rather than having leaves with #f and #f as left/right? I’m using this for Huffman trees, if that helps. Thanks :)
Is a leaf stored in val
or in left, right
?
left, right
So what goes in val?
I don’t think val is actually needed in the trees. I believe you encode and decode purely by counting the branch movements left/right to the desired letter. I just put it there to match the diagrams I was using to see if it matched up alright. The val is the combined weight of the child nodes.
It’s a fine approach.
Great! Thanks.