Question: #include #include using namespace std; / / Define the structure for a node in the binary search tree struct Node { string artist; Node *
#include
#include
using namespace std;
Define the structure for a node in the binary search tree
struct Node
string artist;
Node left;
Node right;
Nodestring name : artistname leftnullptr rightnullptr
;
Function to insert a new artist into the binary search tree
Node insertNode root, string artist
if root nullptr
return new Nodeartist;
if artist rootartist
rootleft insertrootleft, artist;
else if artist rootartist
rootright insertrootright, artist;
return root;
Function to perform an inorder traversal of the binary search tree
void inorderTraversalNode root
if root nullptr
inorderTraversalrootleft;
cout rootartist ;
inorderTraversalrootright;
Function to search for an artist in the binary search tree
bool searchNode root, string artist
if root nullptr
return false;
if rootartist artist
return true;
else if artist rootartist
return searchrootleft, artist;
else
return searchrootright, artist;
Function to find the minimum node in the binary search tree
Node findMinNode root
while rootleft nullptr
root rootleft;
return root;
Function to delete a node from the binary search tree
Node removeNode root, string artist
if root nullptr
return root;
if artist rootartist
rootleft removerootleft, artist;
else if artist rootartist
rootright removerootright, artist;
else
Node to be deleted has one child or no child
if rootleft nullptr
Node temp rootright;
delete root;
return temp;
else if rootright nullptr
Node temp rootleft;
delete root;
return temp;
Node to be deleted has two children
Node temp findMinrootright;
rootartist tempartist;
rootright removerootright, tempartist;
return root;
int main
Node root nullptr;
Initialize the array with the artists
string artistsNasDr Dre", "Snoop Dogg", "JayZ;
int size sizeofartists sizeofartists;
Insert the artists into the binary search tree
for int i ; i size; i
root insertroot artistsi;
Display the initial list of artists
cout s HipHop Concert Lineup" endl;
cout "Initial list of artists: ;
inorderTraversalroot;
cout endl;
int choice;
string newArtist;
bool found;
do
cout Add Artist endl;
cout Remove Artist endl;
cout Display Artists endl;
cout Exit endl;
cout "Enter your choice: ;
cin choice;
switch choice
case :
cout "Enter the name of the artist to add: ;
cin newArtist;
root insertroot newArtist;
cout "Artist successfully added." endl;
break;
case :
cout "Enter the name of the artist to remove: ;
cin newArtist;
found searchroot newArtist;
if found
root removeroot newArtist;
cout "Artist successfully removed." endl;
else
cout "Artist not found in the list." endl;
break;
case :
cout "List of artists: ;
inorderTraversalroot;
cout endl;
break;
case :
cout "Exiting the program." endl;
break;
default:
cout "Invalid choice. Please enter a valid option." endl;
while choice ;
return ;
how to fix declaration error shown
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
