This post contains the program that tests the functions developed in https://jr229931hh1.wixsite.com/website/post/binary_search_tree
City cFromInput(){
City ci;
string n, c; int p;
cout<<"Insert the name, country, and population. ";
cin>>n>>c>>p;
ci.setValues(p,c,n);
return ci;
}
void printCity(City const & c){
cout<<c.name()<<" ("<<c.country()<<","<<c.population()<<")";
}
void printTree(BSTNode* root){
if(root!=nullptr){
printTree(root->left);cout<<" ";
printCity(root->storage);cout<<" ";
printTree(root->right);cout<<" ";
}
}
void printTreeBFS(BSTNode* root){
if(root!=nullptr){
printCity(root->storage);cout<<" ";
printTreeBFS(root->left);cout<<" ";
printTreeBFS(root->right);cout<<" ";
}
}
int main(){
City c;
int option;
cin>>option;
BSTNode* root=nullptr;
while(option!=0){
if(option==1){
c=cFromInput();
root=insert(root,c);
}
if(option==2){
c=cFromInput();
root=delNode(root,c);
}
if(option==3){
printTree(root);
cout<<endl;
}
if(option==4){
printTreeBFS(root);
cout<<endl;
}
if(option==5){
root=deleteMaximum(root);
}
if(option==6){
root=deleteMinimum(root);
}
cin>>option;
}
while(root!=nullptr){
cout<<"Deleting ";
printCity(root->storage);cout<<endl;
root=delNode(root,root->storage);
}
return 0;
}