Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions