// File: bstree.h // // A binary search tree template class #ifndef _bstree_h #define _bstree_h #include "errors.h" // Template parameter TYPE must support: // constrructors, destructors, assignment, copying, comparison, << // template class BSTree ; template class BSTreeNode { friend class BSTree ; public: TYPE data ; // data in each tree node BSTree left ; // left subtree BSTree right ; // right subtree void *operator new(size_t) ; // throws exceptions! void operator delete(void *) ; protected: BSTreeNode() ; // Constructors BSTreeNode(const TYPE&) ; BSTreeNode(const TYPE&, const BSTree&, const BSTree&) ; ~BSTreeNode() ; } ; template class BSTree { public: BSTree() ; ~BSTree() ; void inorder() ; void insert(const TYPE&) ; BSTree *find(const TYPE&) ; // Find node with given key void removeroot() ; // Remove root of the subtree BSTree *min() ; // Find node with smallest key BSTree *max() ; // Find node with largest key bool empty() ; // 1 if empty, 0 otherwise BSTreeNode *root ; // pointer to root BSTreeNode void *operator new(size_t) ; // throws exceptions! void operator delete(void *) ; protected: BSTreeNode *deletemin() ; // remove and return node with min key BSTreeNode *deleteroot() ; // remove and return root node } ; #endif