Hello, I will make a program with c++ about binary tree, how to implement this structure tree to C++
Click Here

Recommended Answers

All 4 Replies

There are a number of ways to go about it, but I'd suggest starting simple. This is an article that cuts right to the chase and doesn't include any fluff that might confuse the core concepts.

Once you have the basics down you can introduce classes to wrap it all up into a nice package.

thank a lot.. :)

Just remember, that inserting already sorted data into a pure binary tree (b-tree) will result in what is effectively a linked list, with unoptimal search characteristics. Once you are able to build a b-tree, then consider building a balanced binary tree. The insert algorithm is more complex as it has to rebalance the tree when necessary, but it will always provide an optimal search performance. This is especially useful for large sets of data. The seminal treatise on this subject is Knuth's "The Art of Computer Programming - Volume 3 - Sorting and Searching".

The article I linked to covers that, and followup articles cover balancing techniques. The problem with Knuth is that it uses a home grown assembly language for code examples. I love the books, don't get me wrong, but translating the code into C++ is more of an intermediate exercise that distracts from the concepts of the data structure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.