Question: Write a C++ program to implement a binary search tree and operate on the binary search tree, which to hold integers with no duplicate starting

Write a C++ program to implement a binary search tree and operate on the binary search tree, which to hold integers with no duplicate starting root = null. All of base code is given, need to add all necessary code. Program need to be run as same as the sample run.

Each line should have an explanation.

# include

# include

# include

# include

# include

# include

# include

using namespace std;

struct node

{

//Define

}*root;

Class BST

{

Public:

find

insert

del

print

BST()

{

root = NULL;

}

};

int main()

{

int choice, num;

string command;

BST bst;

node *temp;

cout<<"-----------------"<

cout<<"Operations on BST"<

cout<<"-----------------"<

cout<<"INSERT "<

cout<<"DELETE "<

cout<<"FIND "<

cout<<"PRINT "<

cout<<"EXIT "<

cout<<"Continue to enter your choice, type EXIT when you are done.";

while (1)

{

vector data;

copy(istream_iterator(cin), istream_iterator(), back_inserter(data));

command = data[0];

transform(command.begin(), command.end(), command.begin(), ::toupper);

if (command == INSERT)

{

}

else if (command == DELETE)

{

}

else if (command == FIND)

{

}

else if (command == PRINT)

{

}

else if (command == EXIT)

{

exit(1);

}

else

{

cout<

}

}

}

INSERT

Output : SUCCESS or DUPLICATE or ERROR

DELETE

Output : SUCCESS or NOTFOUND or ERROR

FIND

Output : SUCCESS or NOTFOUND or ERROR

PRINT

Output : PRINT NULL, if the tree is empty, otherwise print the numbers in sorted order(one per line) and print BEGIN at the start and END at the end(last line).

EXIT

The program is terminated.

Here is sample run:

Sample input

Sample output

PRINT

NULL

INSERT 7

SUCCESS

INSERT 10

SUCCESS

INSERT 98

SUCCESS

INSERT 6

SUCCESS

INSERT 10

DUPLICATE

FIND 98

SUCCESS

FIND 34

NOTFOUND

DELETE 10

SUCCESS

PRINT

BEGIN

6

7

98

END

EXIT

N/A (Program exits)

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!