Archived

This topic is now archived and is closed to further replies.

Creating a binary tree in C

This topic is 5647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am new to C language, and i want help regarding the binary tree ie how to create one(i know creating linked list,stacks & queues).I am trying to make a compression program using huffman algoritm .If any one can help me in this ,please reply.Also tell me names of good books regarding data structures using C/C++.If there is a good site related to above please also tell me that.

Share this post


Link to post
Share on other sites
Your question is in no way related to C - you, sorry, lack any sort of deeper understanding on how a binary tree works, otherwise you would figure out how to make one in C easily.

Get some basic books on algorithms ans data structures - not sure what to suggest right now, look them up in amazon.

Thomas

Share this post


Link to post
Share on other sites
Hmm, I don't know how a remote control really works, otherwise I could build one myself...

Binary trees just use a node with a data element, a left pointer, and a right pointer. The reference to the tree itself is just a pointer to the top node. All nodes may or may not have a left and right branch (If a given direction has no branch, that pointer is set to NULL). Making the binary tree is just a matter of creating nodes and attaching them to the left or right pointer of a given parent node. The end nodes would have both the left and right pointers equal to NULL. What the data element looks like is totally up to you.

As for how you exactly plan to use a binary tree, or parse through it once it is created, is a very different subject. Sorry, I don't have any references for you. But at least you know how to make one now, hopefully. Note that it is possible to create a tree using a method other than creating nodes dynamically (you could, for example, allocate a large array storage and use index references for the branches).

[edited by - Waverider on June 26, 2002 7:52:29 AM]

Share this post


Link to post
Share on other sites
Hi Thomas,
sorry,it was a mistake from my side that i was unable to explain correctly what i really wanted to know.The thing that i wanted to know was,how it is implemented in huffman algorithm.i have a book on data structures but i am not able to follow the explaination given about the huffman algorithm.As for the c language ,i metioned it so that u people may refer me books that teaches data structures using C.once again sorry for not explaining the problem correctly(My English is not very good).

Share this post


Link to post
Share on other sites