C++ tutorial: Binary Search Tree menu


C++ Structure: Building a Binary Search Tree

Step 7: Display BS Tree operations menu


We define a showmenu() function to display a list of choices. We also need another function called select() that allows the user to choose each of the options and decides whether he/he wants to exit the program.

void showmenu(){

  cout<<"=================================\n";
  cout<<"Binary Search Tree Operations Menu\n";
  cout<<"=================================\n";
  cout<<"1.Add a new item\n";
  cout<<"2.Delete an item\n";
  cout<<"3.Show number of items\n";
  cout<<"4.Show all items\n";
  cout<<"5.Show min node\n";
  cout<<"6.Exit\n";


}

void select(){
  int val, ch;
  char yes='y';
  ListElem *Temp;
  while(yes=='y'){
    cout<<"Enter your choice:";cin>>ch;
    switch(ch){
       case 1:
           cout<<"Value:";cin>>val;
           Temp=Insert(&Root,val);
           break;

       case 2:
           cout<<"Value to delete:";cin>>val;
           Temp=Delete(&Root,val);
           break;

      case 3:
          cout<<"All items:\n";
          getallval(Root);
          break;

      case 4:
          Temp=findmin(Root);
          cout<<Temp->data<<endl;
          break;

      case 5:
          Temp=findmax(Root);
          cout<<Temp->data<<endl;
          break;

      case 6:
         cout<<"Value:";cin>>val;
         Temp=find(Root,val);
         cout<<Temp->data;
         break;

      case 7: exit(0);

      default: cout<<"Invalid choice";

     }
   cout<<"Continue?y/n:";cin>>yes;
 }

   Temp=NULL;
}




Comments

ralph comment

 ralph

none


2017-01-12
ralph comment

 ralph

none


2017-01-12



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.