Write a program in C++ to create a Binary Search tree (BST) of string data. The program will perform these operations: Insert name(s), Traverse Preorder, Search name, Delete name, Leaf Count, sibling of a person and Quit.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

(please answer the question in c++ i need the nodes to be able to accept strings like "KIM" used in the example)

 

Option 4:         Deletes a name from the BST.

                        It will prompt: Enter name you want to delete: TOM

 

                        If the name is found then delete the name from the BST and displays the message –“___ is deleted.” If the name is not in the BST, then it will display – “____ is not found in the BST”

 

                        TOM is deleted

 

Option 5:         Counts the number of leaves in the BST and displays –

                        “There are ____ number of leaves in the BST.”

 

Option 6:         Enter a name and it will display the sibling of that person.

                        It will prompt: Enter the name you want to find the sibling of:

                       

                        The sibling of ____ is _____

                        If the person has no sibling, then it displays:

                        ____ has no sibling.

                        Ex:       Enter the item:            PAM

                       

                        The sibling of PAM is DON.

 

Option 7:         Quit the program.

 

           

Write a program in C++ to create a Binary Search tree (BST) of string data. The program will
perform these operations: Insert name(s), Traverse Preorder, Search name, Delete name, Leaf
Count, sibling of a person and Quit.
Use this header file:
class BT
{
private:
public:
};
struct node
{
string data;
node* left;
node* right;
node* root;
BT();
bool isEmpty() const { return root == NULL; }
void insert(string);
void print preorder();
void preorderTrav(node*);
void searchBST(string);
void deleteNode(string);
int count();
int leafCount (node*);
void nodeSibling (string);
Use the following menu in your program. Must place your name in the menu heading.
1.
2.
3.
4.
5.
6.
7.
//Constructor
//Check for empty
//Insert item in BST
//Preorder traversing driver
//Preorder traversing
//Searches BST for a specific node
//Delete item in BST
//Count driver
//Counts number of leaves in BST
//Finds sibling of a node
Insert name(s)
Traverse Preorder
Search name
Delete name
Leaf Count
Sibling of a person
Quit
Enter your choice:
Use the following names in the given order to form the BST tree:
KIM PAM DON TOM RON BEN AMY
Transcribed Image Text:Write a program in C++ to create a Binary Search tree (BST) of string data. The program will perform these operations: Insert name(s), Traverse Preorder, Search name, Delete name, Leaf Count, sibling of a person and Quit. Use this header file: class BT { private: public: }; struct node { string data; node* left; node* right; node* root; BT(); bool isEmpty() const { return root == NULL; } void insert(string); void print preorder(); void preorderTrav(node*); void searchBST(string); void deleteNode(string); int count(); int leafCount (node*); void nodeSibling (string); Use the following menu in your program. Must place your name in the menu heading. 1. 2. 3. 4. 5. 6. 7. //Constructor //Check for empty //Insert item in BST //Preorder traversing driver //Preorder traversing //Searches BST for a specific node //Delete item in BST //Count driver //Counts number of leaves in BST //Finds sibling of a node Insert name(s) Traverse Preorder Search name Delete name Leaf Count Sibling of a person Quit Enter your choice: Use the following names in the given order to form the BST tree: KIM PAM DON TOM RON BEN AMY
Option 1:
Option 2:
Option 3:
Inserts name(s) in a BST.
Enter Your Choice <1-7> 1
Enter number of items to insert: 4
Enter node: KIM
Inserted.
Enter node: PAM
Inserted.
Enter node: DON
Inserted.
Enter node: TOM
Inserted.
Traverse the tree in Preorder and display the node info and its left child info and
right child info. If a node does not have a child then display NIL.
Enter Your Choice <1-7>2
Sample output:
Node Info
KIM
DON
PAM
TOM
Traversing Preorder
Left Child Info Right Child Info
DON
NIL
NIL
NIL
PAM
NIL
Search for the name in the BST.
It will prompt: Enter name you want to search for: KIM
KIM
ΤΟΜ
NIL
If the name is found, then display the name and the left child information and right
child information. If the item is not found, then it will display – “ is not found
in the BST"
Node Info Left Child Info Right Child Info
DON
PAM
Transcribed Image Text:Option 1: Option 2: Option 3: Inserts name(s) in a BST. Enter Your Choice <1-7> 1 Enter number of items to insert: 4 Enter node: KIM Inserted. Enter node: PAM Inserted. Enter node: DON Inserted. Enter node: TOM Inserted. Traverse the tree in Preorder and display the node info and its left child info and right child info. If a node does not have a child then display NIL. Enter Your Choice <1-7>2 Sample output: Node Info KIM DON PAM TOM Traversing Preorder Left Child Info Right Child Info DON NIL NIL NIL PAM NIL Search for the name in the BST. It will prompt: Enter name you want to search for: KIM KIM ΤΟΜ NIL If the name is found, then display the name and the left child information and right child information. If the item is not found, then it will display – “ is not found in the BST" Node Info Left Child Info Right Child Info DON PAM
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education