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

C

cricketunes

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
 
S

serrand

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top