Hello, i have create a human tree, the only remains is to get the codes in Huffman tree (0-Left, 1-Right)
How i can traverse the tree and for every letter-weight in tree to get the path of 0101
How my code works
1st Part - Nodes Initialisation
- Create Tree Noodes BTree* Nodes
- for(int i=0; i < MAX_ALPHABET_LETTERS; i++) Initialise Nodes with theyr Weight & Letters (Weights and Letters are defined)
- For every node i create, i add it to a sorted list
2nd Part - Building the tree
As i say, i store nodes to the sorted list, that means always the first 2 elemnts on list are the smallers (No need extra code to get smallest elements)
What i need?
I need help to get & store codes in Builded Tree
This maby will help you
- All nodes of tree are stored in global list, So, what you think about:
"descent the list (from higer to smaller) and foreach node in list check if it has Left or Right"
"If it has Right then go to the right node and add 1 to node struct"
"If it has Left then go to the left node and add 0 to node data"
The lowest nodes in tree has as code the value of his upper node + "0" or "1" (if it is left or right)
Edited 3 Years Ago by Cwww