#include "BinaryTree.h" class BinarySearchTree { // uses the class BinaryNode private: BinaryNode *root; // some private functions will be here public: // constructor class EmptyTree : public RuntimeException { public: EmptyTree() : RuntimeException("tree is empty") {} }; class ItemNotFound : public RuntimeException { public: ItemNotFound() : RuntimeException("item not found") {} }; class DuplicateItem : public RuntimeException { public: DuplicateItem() : RuntimeException("duplicate item") {} }; BinarySearchTree( ) { root = NULL; } ~BinarySearchTree( ) { BinaryTree::deleteTree(root); root = NULL; } long size() {return (root==NULL) ? 0 : root->size(root);} int height() {return (root==NULL) ? 0 : root->height(root);} BinaryNode* findMin(BinaryNode *t) throw(EmptyTree); BinaryNode* removeMin(BinaryNode *t) throw(ItemNotFound); BinaryNode *find(int x,BinaryNode *t) throw(ItemNotFound ); BinaryNode *insert(int x,BinaryNode *t) throw(DuplicateItem); BinaryNode* remove(int x,BinaryNode *t) throw(ItemNotFound); void insert(int x) throw(DuplicateItem) { root = insert(x, root); } void remove(int x) throw(ItemNotFound) { root = remove(x, root); } void traverse(BinaryNode *t) throw(ItemNotFound); BinaryNode *find(int x) throw(ItemNotFound) { return find(x, root); } bool isEmpty( ){ return root == NULL; } void display() const {display(root);} void display(BinaryNode *t) const; long sum(BinaryNode *t) const; long sum() const {return sum(root);} };