Index

Implementing Binary Trees


Back


C++ Data Type Implementations

Almost every programmer has had to deal with implementing some form of data type using their programming language of choice. C programmers that have switched over to C++ may have had a hard time working on an implementation without defaulting to using C functions outside the data class to operate on the data, or using void pointers to handle generic classes. Hopefully this page will help clarify some things and make some of the powerful tools in C++ more apparent.


Implementing Trees

Binary Trees are probably one of the hardest to implement using C++, and even implemented properly, still require a few preconditions for it to work. The implementation that I will demonstrate requires that the data you store in the tree is dynamically allocated, or allocated at or near the base of the stack so that the Tree will remain valid throughout your program. It also requires that you write some way of retrieving and deleting the dynamic data on your own. However, I will show you how you can use Traversal member functions to traverse the tree and get the data before you deallocate the tree.