// File: bstree.h // // A binary search tree class // The following declaration tell the compiler that the symbol // "BSTreeNode" is a class, before we fully define the class. // This allows us to use pointers to BSTreeNode in BSTree. // Think of it as a class "prototype". class BSTreeNode ; // Simple example of "extra" data stored in a node // typedef char data ; class BSTree { public: BSTree() ; ~BSTree() ; void Inorder() ; void Insert(int) ; void Insert(int, data) ; BSTree *Search(int) ; // 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 int IsEmpty() ; // 1 if empty, 0 otherwise int RootKey() ; // Do stuff with root of tree, data *RootDataPtr() ; // requires non-empty tree void RootPrint() ; protected: BSTreeNode *root ; // pointer to root BSTreeNode BSTreeNode *ExtractMin() ; // remove and return node with min key BSTreeNode *ExtractRoot() ; // remove and return root node } ; class BSTreeNode { friend class BSTree ; public: data stuff ; // stuff other than key in the tree void Print() ; // Can have other member functions. protected: int key ; // ordering in tree is based on key BSTreeNode() ; // Constructors BSTreeNode(int) ; BSTreeNode(int, data) ; ~BSTreeNode() ; // protected destructor BSTree left ; // left subtree BSTree right ; // right subtree } ;