recursive loops are not my strong side so i need some help:
ive made a huffman tree, which consist of two elements: leaves and nodes (leaves carry the character information, the nodes get calculated). each node has the information of which two elements came before (called leftElement and rightElement). per isLeaf() you can test if its a leaf and therefore you reached the end of a brunch.
to create an easy tree i sort the leaves at the beginning so that each huffman tree looks like this: e.g.:
10% 20% 30% 40%
A B C D
| | | | | |
Node1 | | | |
|-------------- Node2 | |
| | |
----------- Node3
hope it doesnt look too confusing =)
now my problem: i need to generate the code itself with an recursion so that every node/leaf gets walked through an for each left branch a ‘0’ is remembered and for each right branch a ‘1’. important is, that i need to save the result after a leave is reached.
i had some experiments, but no good result.
