Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming Please use the attached Header file to create both implementation and source files. Thanks, Use the below attached header file to Write a

C++ Programming

Please use the attached Header file to create both implementation and source files. Thanks,

image text in transcribed

image text in transcribed

image text in transcribed

Use the below attached header file to 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 the following menu in your program. Must place your name in the menu heading. Use the following names in the given order to form the BST tree: KIM PAM DON TOM RON BEN AMY (Hints: 1. Before you start working on the program, you draw the BST for the given order of the above names. It will help you check your output for the options in the menu. 2. While working on the program, enter fewer names for testing - such as KIM, PAM, DON and TOM. You work on one menu at a time then it will be easier to test and manage the program instead of writing the whole program for the entire menu then test your program.) Option 1: Inserts name(s) in a BST. Enter Your Choice 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 2 Sample output: Search for the name in the BST. It will prompt: Enter name you want to search for: KIM 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" 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" Counts the number of leaves in the BST and displays "There are number of leaves in the BST." 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 Attachment 1: Use this header file to create the implementation and source files with the above instructions. \#include \#ifndef BT_H \#define BTH class BT \{ private: struct node \{ string data; node* left; node* right: \} ; public: node* root; BT(); //Constructor bool iskmety( ) const { return root == NULL; }// Check for empty void insert(string); //Insert item in BST void print,preorder(); //Preorder traversing driver void preorderTrav(node*); //Preorder traversing void searchBSL(string); //Searches BST for a specific node void deleteNode(string); //Delete item in BST int count(); //Count driver int leafcount(node*); //Counts number of leaves in BST void nodesibling(string); //Finds sibling of a node \}

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

Students also viewed these Databases questions