class Tree { private: // class TNode is private to the Tree class. // nobody outside this class needs to know what nodes look like. class TNode { public: // a very open class... int data; // int to keep life simple // . . . other data could be added here if desired TNode *left, *right; TNode (int data, TNode *left, TNode *right) { TNode::data = data; TNode::left = left; TNode::right = right; } }; TNode *root; // root pointer int size; // number of values in the tree // deletes all of the nodes in a specified subtree void purge (TNode* subroot); // displays a subtree graphically using specified prefix strings void subDisplay (String2002 leftPreString, String2002 midPreString, String2002 rightPreString, TNode *subRoot); public: // simple methods are often implemented directly in the header file. // this goes somewhat against the principle of "hiding" as many implementation // details as possible in the header file, but does keep things simpler. Tree () { // default constructor root = NULL; size = 0; } ~Tree(); // destructor // returns true if insertion successful (data does not already exist) // and false otherwise. bool insert (int data); // returns true if deletion successful (data existed in tree) // and false otherwise. bool remove (int data); // outputs tree graphically to "cout" void display (); // performs an LL rotation at the node containing the specified data value. // returns true if the rotation was successfully performed and false otherwise // (value not in tree or the node lacks a left child). bool rotateLL (int data); // performs an RR rotation at the node containing the specified data value. // returns true if the rotation was successfully performed and false otherwise // (value not in tree or the node lacks a right child). bool rotateRR (int data); // returns the height of the tree and sets "isBalanced" to true or // false depending upon whether tree is balanced. int height (bool &isBalanced); };