Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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

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_2

Step: 3

blur-text-image_3

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

=+and reduction in force, and intellectual property.

Answered: 1 week ago