Question: For this computer assignment, implement a derived class (as a template) to represent a binary search tree. Since a binary search tree is a binary
For this computer assignment, implement a derived class (as a template) to represent a binary search tree. Since a binary search tree is a binary tree, implement your binary search tree class from the base class of the binary tree as you implemented in your previous assignment.
The definition of the derived class of a binary search tree (as a template) is given as follows
template < class T >
class binSTree : public binTree < T > { public: void insert ( const T& x ); // inserts node with value x
bool search ( const T& x ) const; // searches leaf with value x
bool remove ( const T& x ); // removes leaf with value x
private:
void insert ( Node < T >*&, const T& ); // private version of insert
bool search ( Node < T >*, const T& ) const;// private version of search
void remove ( Node < T >*&, const T& ); // private version of remove
bool leaf ( Node < T >* node ) const; // checks if node is leaf
};
The insert ( ) function inserts a node with the data value x in the tree. For the search ( ) function, x is the data value of a leaf to be searched for. If the search is successful, the search ( ) function returns true; otherwise, it returns false. The remove ( ) function first calls the search ( ) function to determine the result of the search for a leaf with the data value x, and if the search is successful, then it calls the private version of the remove ( ) function to remove the corresponding leaf from the tree and returns true; otherwise, it returns false. The leaf ( ) function simply checks if a node is a leaf.
The private versions of the member functions insert ( ), remove ( ) and search ( ) can be implemented as recursive functions, but these functions have an additional argument, which is the root of the tree. The private version of the remove ( ) function unlike its public version does not return any value.
*Just do the binSTree.h file in c++ please* I have the binTree.h file finished.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
