#include <DS_BinarySearchTree.h>
Inheritance diagram for DataStructures::BinarySearchTree< BinarySearchTreeType >:
Public Member Functions | |
BinarySearchTree (const BinarySearchTree &original_type) | |
BinarySearchTree & | operator= (const BinarySearchTree &original_copy) |
unsigned int | Size (void) |
void | Clear (void) |
unsigned int | Height (node *starting_node=0) |
node * | Add (const BinarySearchTreeType &input) |
node * | Del (const BinarySearchTreeType &input) |
bool | IsIn (const BinarySearchTreeType &input) |
void | DisplayInorder (BinarySearchTreeType *return_array) |
void | DisplayPreorder (BinarySearchTreeType *return_array) |
void | DisplayPostorder (BinarySearchTreeType *return_array) |
void | DisplayBreadthFirstSearch (BinarySearchTreeType *return_array) |
BinarySearchTreeType *& | GetPointerToNode (const BinarySearchTreeType &element) |
Protected Types | |
enum | Direction_Types { NOT_FOUND, LEFT, RIGHT, ROOT } |
Protected Member Functions | |
unsigned int | HeightRecursive (node *current) |
node *& | Find (const BinarySearchTreeType &element, node **parent) |
node *& | FindParent (const BinarySearchTreeType &element) |
void | DisplayPostorderRecursive (node *current, BinarySearchTreeType *return_array, unsigned int &index) |
void | FixTree (node *current) |
Protected Attributes | |
node * | root |
enum DataStructures::BinarySearchTree::Direction_Types | direction |
unsigned int | BinarySearchTree_size |
Classes | |
struct | node |
Initilize with the following structure
BinarySearchTree<TYPE>
OR
AVLBalancedBinarySearchTree<TYPE>
Use the AVL balanced tree if you want the tree to be balanced after every deletion and addition. This avoids the potential worst case scenario where ordered input to a binary search tree gives linear search time results. It's not needed if input will be evenly distributed, in which case the search time is O (log n). The search time for the AVL balanced binary tree is O (log n) irregardless of input.
Has the following member functions unsigned int Height(<index>) - Returns the height of the tree at the optional specified starting index. Default is the root add(element) - adds an element to the BinarySearchTree bool del(element) - deletes the node containing element if the element is in the tree as defined by a comparison with the == operator. Returns true on success, false if the element is not found bool IsInelement) - returns true if element is in the tree as defined by a comparison with the == operator. Otherwise returns false DisplayInorder(array) - Fills an array with an inorder search of the elements in the tree. USER IS REPONSIBLE FOR ALLOCATING THE ARRAY!. DisplayPreorder(array) - Fills an array with an preorder search of the elements in the tree. USER IS REPONSIBLE FOR ALLOCATING THE ARRAY!. DisplayPostorder(array) - Fills an array with an postorder search of the elements in the tree. USER IS REPONSIBLE FOR ALLOCATING THE ARRAY!. DisplayBreadthFirstSearch(array) - Fills an array with a breadth first search of the elements in the tree. USER IS REPONSIBLE FOR ALLOCATING THE ARRAY!. clear - Destroys the tree. Same as calling the destructor unsigned int Height() - Returns the height of the tree unsigned int size() - returns the size of the BinarySearchTree GetPointerToNode(element) - returns a pointer to the comparision element in the tree, allowing for direct modification when necessary with complex data types. Be warned, it is possible to corrupt the tree if the element used for comparisons is modified. Returns NULL if the item is not found
EXAMPLE
BinarySearchTree<int> A; A.Add(10); A.Add(15); A.Add(5); int* array = new int [A.Size()]; A.DisplayInorder(array); array[0]; // returns 5 array[1]; // returns 10 array[2]; // returns 15
clear - empties the BinarySearchTree and returns storage The assignment and copy constructors are defined