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;
Node(string name) : artist(name), left(nullptr), right(nullptr){}
};
// Function to insert a new artist into the binary search tree
Node* insert(Node* root, string artist){
if (root == nullptr){
return new Node(artist);
}
if (artist root->artist){
root->left = insert(root->left, artist);
} else if (artist > root->artist){
root->right = insert(root->right, artist);
}
return root;
}
// Function to perform an inorder traversal of the binary search tree
void inorderTraversal(Node* root){
if (root != nullptr){
inorderTraversal(root->left);
cout root->artist "";
inorderTraversal(root->right);
}
}
// Function to search for an artist in the binary search tree
bool search(Node* root, string artist){
if (root == nullptr){
return false;
}
if (root->artist == artist){
return true;
} else if (artist root->artist){
return search(root->left, artist);
} else {
return search(root->right, artist);
}
}
// Function to find the minimum node in the binary search tree
Node* findMin(Node* root){
while (root->left != nullptr){
root = root->left;
}
return root;
}
// Function to delete a node from the binary search tree
Node* remove(Node* root, string artist){
if (root == nullptr){
return root;
}
if (artist root->artist){
root->left = remove(root->left, artist);
} else if (artist > root->artist){
root->right = remove(root->right, artist);
} else {
// Node to be deleted has one child or no child
if (root->left == nullptr){
Node* temp = root->right;
delete root;
return temp;
} else if (root->right == nullptr){
Node* temp = root->left;
delete root;
return temp;
}
// Node to be deleted has two children
Node* temp = findMin(root->right);
root->artist = temp->artist;
root->right = remove(root->right, temp->artist);
}
return root;
}
int main(){
Node* root = nullptr;
// Initialize the array with the artists
string artists[]={"Nas","Dr. Dre", "Snoop Dogg", "Jay-Z"};
int size = sizeof(artists)/ sizeof(artists[0]);
// Insert the artists into the binary search tree
for (int i =0; i size; ++i){
root = insert(root, artists[i]);
}
// Display the initial list of artists
cout "90's Hip-Hop Concert Lineup" endl;
cout "Initial list of artists: ";
inorderTraversal(root);
cout endl;
int choice;
string newArtist;
bool found;
do {
cout "1. Add Artist " endl;
cout "2. Remove Artist " endl;
cout "3. Display Artists " endl;
cout "4. Exit " endl;
cout "Enter your choice: ";
cin >> choice;
switch (choice){
case 1:
cout "Enter the name of the artist to add: ";
cin >> newArtist;
root = insert(root, newArtist);
cout "Artist successfully added." endl;
break;
case 2:
cout "Enter the name of the artist to remove: ";
cin >> newArtist;
found = search(root, newArtist);
if (found){
root = remove(root, newArtist);
cout "Artist successfully removed." endl;
} else {
cout "Artist not found in the list." endl;
}
break;
case 3:
cout "List of artists: ";
inorderTraversal(root);
cout endl;
break;
case 4:
cout "Exiting the program." endl;
break;
default:
cout "Invalid choice. Please enter a valid option." endl;
}
} while (choice !=4);
return 0;
}
how to fix declaration error shown
#include #include using namespace std; / / Define

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 Finance Questions!