440,965 Members | 1,757 Online
Need help? Post your question and get tips & solutions from a community of 440,965 IT Pros & Developers. It's quick & easy.

# How do I know if I am moving left or right in a binary tree?

 P: n/a Hey folks I am implementing the Huffman encoding algorithm. I have created the tree and its perfect. Now while searching for a node value, I need to write a 0 to the encoded file if I am moving left and 1 if I am moving right. How will I know if I am moving left or right? For instance if I go to the bottom of the left leaf and its leaflets and then come back and find the value in one of the right leaves, I shouldnt be having all those 00000s right? Appreciate your ideas Thanks Crickie Feb 21 '06 #1

 P: n/a cr*********@yahoo.com wrote: Hey folks I am implementing the Huffman encoding algorithm. I have created the tree and its perfect. Now while searching for a node value, I need to write a 0 to the encoded file if I am moving left and 1 if I am moving right. How will I know if I am moving left or right? For instance if I go to the bottom of the left leaf and its leaflets and then come back and find the value in one of the right leaves, I shouldnt be having all those 00000s right? Appreciate your ideas Thanks Crickie Despite your question is not c specific... What did you put in your tree? What is it for? Hufman's tree is useful to create table for encoding... it's just a mean in order to create new alphabet from sorted alphabet Having your tree, if leaves value is a character of your alphabet, go left to right in order to produce your conversion's table... just note you have turn left or right by shifting 1 or 0 in an int variable code = (code << 1) & direction; /* 0 or 1 */ size_of_code++; when you are in the leaf... you read the letter, associates the code Be systematc.. Xavier Feb 21 '06 #2

### This discussion thread is closed

Replies have been disabled for this discussion.