Binary Search Tree Code
Here is the sample code for a Binary Search Tree class, as discussed in class, together with a sample main program to test the class.
The BinSTree.cpp file contains the code for the BST class. While everything should be working fine (I hope), this class is not really an "industrial strength" class, for several reasons:
Documentation is non-existent | |
The internal private functions findNode and findParent are inefficient in the sense that they both do almost the same thing, and they are usually used together. It would be more efficient to create one function findNodeAndParent that would return a pointer to a node, if possible, and the parent to that node in one call. | |
The isFull method always returns false (i.e. the class assumes "infinite" memory is available), and insert does not check whether the tree is full before attempting to insert a new node | |
The class currently works with ElementType and KeyType being identical (integer). For a useful class a more flexible ElementType should be defined (as a separate class) |
In any case, here is the code for those who are interested:
BinSTree.cpp (the Binary Search Tree class) | |
TreeTest.cpp (a simple main test function) |