- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# DataStructures::BinarySearchTree< BinarySearchTreeType > Class Template Reference

A binary search tree and an AVL balanced binary search tree. More...

`#include <DS_BinarySearchTree.h>`

Inheritance diagram for DataStructures::BinarySearchTree< BinarySearchTreeType >:

List of all members.

## 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

## Detailed Description

### template<class BinarySearchTreeType>
class DataStructures::BinarySearchTree< BinarySearchTreeType >

A binary search tree and an AVL balanced binary search tree.

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

compress - reallocates memory to fit the number of elements. Best used when the number of elements decreases

clear - empties the BinarySearchTree and returns storage The assignment and copy constructors are defined

Note:
  The template type must have the copy constructor and assignment operator defined and must work with >, <, and == All elements in the tree MUST be distinct The assignment operator is defined between BinarySearchTree and AVLBalancedBinarySearchTree as long as they are of the same template type. However, passing a BinarySearchTree to an AVLBalancedBinarySearchTree will lose its structure unless it happened to be AVL balanced to begin with Requires queue_linked_list.cpp for the breadth first search used in the copy constructor, overloaded assignment operator, and display_breadth_first_search.

The documentation for this class was generated from the following file:

- C:/RakNet 2.518/Include/DS_BinarySearchTree.h