C++ exercises solutions: linked list menu of choices


Circularly Linked List

Menu of circularly Linked List

Step 8: Display a menu of choices

To show the menu that allow the user to choose an operation on the linked list, you need the showmenu() and select() functions as shown below:

void showmenu(){

  cout<<"=================================\n";
  cout<<"Circularly Linked List 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.Find min item\n";
  cout<<"5.Find max item\n";
  cout<<"6.Find item\n";
  cout<<"7.Print all items\n";
  cout<<"8.Exit\n";


}

void select(){
  int val, pos, ch;
  ListElem *temp;
  char yes='y';
  makeEmpty();//Make the list empty
  while(yes=='y'){
     cout<<"Enter your choice:";cin>>ch;
     switch(ch){
     case 1:
        cout<<"Value:";cin>>val;
        cout<<"Position:";cin>>pos;
        Insert(val,pos);
        break;
    case 2:
        cout<<"Position:";cin>>pos;
        Delete(pos);
        break;
    case 3:
        cout<<"Number of items:"<<countitem(pfirst);
        break;
    case 4:
        temp=findmin(pfirst);
        if(temp!=NULL)
            cout<<"The min item:"<<temp->data<<endl;
       else cout<<"Not found\n";
       break;
    case 5:
       temp=findmax(pfirst);
       if(temp!=NULL)
          cout<<"The max item:"<<temp->data<<endl;
      else cout<<"Not found\n";

      break;
    case 6:
       cout<<"Find what:";cin>>val;
       temp=find(pfirst,val);
       if(temp!=NULL)
           cout<<"The found item:"<<temp->data<<endl;
       else cout<<"Not found\n";
       break;
     case 7:
        cout<<"All items:\n";
        printall(pfirst);
        break;
     case 8: exit(0);

     default: cout<<"Invalid choice\n";

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

}




Comments

d comment

 d

Fuck you russia, russia is very stupid country in the world


2018-03-14
ყლე comment

 ყლე

ტრაკში ყლე პირში ბაუნტი


2018-03-14
ყლე comment

 ყლე

დიდი ყლე


2018-03-14
usama comment

 usama

nyc



2017-04-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.