Question: BinarySearchTree.h #ifndef BinarySearchTree _ h #define BinarySearchTree _ h #include #include using namespace std; / / * * * * * * * * class
BinarySearchTree.h
#ifndef BinarySearchTreeh
#define BinarySearchTreeh
#include
#include
using namespace std;
class TreeNode template object
template
struct TreeNode;
template
ostream& operator ostream& os const TreeNode& node;
template
class BinarySearchTree;
template
ostream& operator ostream& os const BinarySearchTree& tree;
template
class TreeNode
public:
friend ostream& operator ostream& os const TreeNode& node
os node.data ;
ifnodeleft NULL
os nodeleft;
else os ;
os ;
ifnoderight NULL
os noderight;
else os ;
os ;
return os;
TreeNode parent;
TreeNode left;
TreeNode right;
T data;
;
The following help functions are for class TreeNode object
template
bool isLeafTreeNode node
ifnode NULL return false;
return nodeleft NULL && noderight NULL;
template
bool isRightTreeNode node
ifnode NULL nodeparent NULL return false;
return node nodeparentright;
template
bool isLeftTreeNode node
ifnode NULL nodeparent NULL return false;
return node nodeparentleft;
template
bool isRootTreeNode node
ifnode NULL return false;
return nodeparent NULL;
template
int treeHeightTreeNode node
ifnode NULL return ;
return maxtreeHeightnodeleft treeHeightnoderight;
template
int treeSizeTreeNode node
ifnode NULL
return ;
return treeSizenodeleft treeSizenoderight;
Public and private member functions from BinarySearchTree class
Implement all the member public and private functions from BinarySearchTree class
All function names explain the purpose of their function
template class BinarySearchTree
public:
friend ostream& operator ostream& os const BinarySearchTree& tree
os treeroot;
return os;
BinarySearchTree;
TreeNode searchT& data const;
void insertT& data;
TreeNode successorTreeNode node const;
bool removeT& data;
bool isEmpty const;
int height const;
int size const;
string toString const;
TreeNode getRoot const;
private:
TreeNode root;
bool removeTreeNode node;
;
#endif BinarySearchTreeh
CSCIProjFour.cpp
#include
#include "BinarySearchTree.h
using namespace std;
void menu
cout
;
cout MENU
;
cout Add a node
;
cout Remove a node
;
cout Search a data
;
cout Tree property
;
cout Quit
;
cout
;
int main
int data;
int choice;
BinarySearchTree tree;
do
menu;
cout "Enter your choice: ;
cin choice;
switchchoice
case :
cout "Enter an integer data that you will add to tree: ;
cin data;
tree.insertdata;
cout "The tree is: tree endl;
break;
case :
cout "Enter an integer data that you will remvoe from tree: ;
cin data;;
iftreeremovedata
cout "Remove successfully. Now the tree is: tree endl;
else
cout No such data in tree
;
break;
case :
cout "Enter the integer data that you want to search for:
;
cin data;
iftreesearchdata NULL
cout No such data in tree
;
else
cout "The tree is: tree Data found in tree
;
break;
case :
iftreeisEmpty
cout "Tree is empty
;
else
cout "The tree is: tree endl;
cout "Tree size: tree.size endl;
cout "Tree height: tree.height endl ;
break;
case :
cout "Make sure you run enough test before you turn it in
;
break;
default:
cout "Wrong option. Please choose from menu
;
break;
whilechoice ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
