Question: Implement a binary search tree. class treeNode { private: treeNode( int D, treeNode* lt = NULL, treeNode* rt = NULL ) { left = lt;

Implement a binary search tree.

class treeNode

{

private:

treeNode( int D, treeNode* lt = NULL, treeNode* rt = NULL )

{ left = lt; data = D; right = rt; }; // constructor

treeNode* left; // pointer to the left subtree

int data; // node data

treeNode* right; // pointer to the right subtree

friend class searchTree; // give searchTree complete access

};

class searchTree

{

public:

searchTree(); // constructor

searchTree( const searchTree& ); // copy constructor

~searchTree(); // destructor

searchTree& operator=(const searchTree&); // overloaded assignment bool find( int ); // find a value in the tree

void insert( int ); // add a new value to the tree

void remove( int ); // remove a value from the tree

void inorder() const; // display the tree inorder (sorted order)

void preorder() const; // display the tree preorder

void postorder() const; // display the tree postorder

void level_by_level() const; // display the tree level_by_level

int height() const; // display the height of the tree

int nodeCount() const; // display the number of nodes in the tree

int leafCount() const; // display the number of leaves in the tree

private:

treeNode* root; // pointer to the root of the search tree

// you will probably want to add additional pointer variables and

// functions to facilitate the manipulation of the search tree.

};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!