how can i create a program that provides 3 types of data structures: linked list, stack and queue.which my program will provide a menu that a user can choose whether to use a linked list, stack or queue.

Example of output:
Main Menu
1. Linked list
2. Stack
3. Queue
4. Exit
Enter your choice:
Linked list Menu
1. Insert a number
2. Remove a number
3. Display the list of number in a descending order
4. Back to the main menu
Stack Menu
1. Insert a variable’s address
2. Remove the address
3. Display the Memory stack
4. Back to the main menu
Queue Menu
1. Insert a printer’s id and location
2. Remove one record
3. Display the records
4. Back to the main menu

Recommended Answers

All 3 Replies

To repeat many replies in this forum - we don't do your homework for you - that is cheating (not to mention unethical). Make an honest effort to do the assignment and we will be happy to critique it, and point out errors that new programmers are likely to make (which you will certainly emulate).

i know about that but i just want to know the way on how to solve it..not 100% ask all the forumer do my job..

I have the three types of data structure full coding..but I dont know how to combine all of these into one..

Link List

#include<iostream.h>
#include<string>
   using namespace std;

   struct node // struct node for linked list
   {
      int iNom;
      node *next;
   };

   void insert();
   void remove();
   void display();
   node *head;  

   void main()
   {    
      head=NULL;
      int choice;
      do{
         cout<<"\n\n******************************";
         cout<<"\n       LINKED LIST MENU        ";
         cout<<"\n******************************";    
         cout<<"\n\t1. INSERT"<<endl;
         cout<<"\t2. REMOVE"<<endl;
         cout<<"\t3. DISPLAY"<<endl;
         cout<<"\t4. EXIT"<<endl;
         cout<<"\n\nPlease enter your choice: ";
         cin>>choice;
         switch(choice){
            case 1:
               insert();                                                                    
               break;
            case 2:
               remove();                                                                    
               break;
            case 3:
               display();                                                                   
               break;
            default:
               cout<<"Invalid Choice";
               break;
         }
      }while(choice!=4);    


   }

   void insert() //function insert
   { 
      node *newptr,*prev,*cur;
      newptr = new node;
      cout<<"\n*********************"<<endl;
      cout<<"        INSERT       ";
      cout<<"\n*********************"<<endl;
      cout<<"\nPlease Enter A Number : ";
      cin>>newptr->iNom;
      cout<<"\nThe New Number Has been Inserted"<<endl;
      newptr->next=NULL;  // pointer next is NULL

      if(head==NULL)
      {
         head=newptr; 
      }
      else
      {
         while(newptr->iNom > cur->iNom && cur!=NULL)   
         {
            prev=cur;   
            cur=cur->next;  
         }
         if(prev==NULL) 
         {
            newptr->next=head;  
            head=newptr;                                                    
         }
         else
         {
            newptr->next=cur;   
            prev->next=newptr;  
         }
      }
   }

   void remove() 
   {
      int iNumber;
      node *newptr; node *cur , *prev;
      prev=NULL;
      cur=head;iNumber;
      cout<<"\n*********************"<<endl;
      cout<<"        REMOVE       ";
      cout<<"\n*********************"<<endl;
      while(cur != NULL) 
      {
         cout<<endl<<"\t    "<<cur->iNom; 
         cur = cur->next;
      }

      cout<<"\nEnter the number which one you want to DELETE: ";
      cin>>iNumber;

      if(head==NULL)        
      {
         cout<<"\nNo Data found!";
      }
      else 
      {
         while(cur!=NULL&&iNumber!=cur->iNom)
         {
            prev=cur;
            cur=cur->next;
         }
         if(prev==NULL)
         {
            head=head->next;
            delete cur;
         }
         else if(cur==NULL)
         {
            cout<<"Sorry! Your data is invalid!";
         }
         else
         {
            prev->next=cur->next;
            delete cur;
         }
      }
   }

   void display()   //function display
   {    
      node *cur;
      cur=head; 
      cout<<"\n*********************"<<endl;
      cout<<"\tDISPLAY       ";
      cout<<"\n*********************"<<endl;

      if(head == NULL)
      {
         cout<<"\nYour data is empty\n";
      }
      else
      {
         while(cur!=NULL)   
         {
            cout<<endl<<"\t         "<<cur->iNom; 
            cur = cur->next;     
         }
      }
   }

Stack

#include<iostream.h>
#include<string>
   using namespace std;

   struct stack //struct name with stack                                                    
   {
      string address;
      stack *next;
   };
   stack *top;
   void push();
   void pop();
   void display();

   void main()
   {   
      top = NULL;
      int choice;
      do{ 
         cout<<"\n\n******************************";
         cout<<"\n       STACK MENU        ";
         cout<<"\n******************************";    
         cout<<"\n\t1. PUSH"<<endl;
         cout<<"\t2. POP"<<endl;
         cout<<"\t3. DISPLAY"<<endl;
         cout<<"\t4. EXIT"<<endl;
         cout<<"\n\nPlease enter your choice: ";
         cin>>choice;
         switch(choice){
            case 1:
               push();  /* call function push()*/
               break;
            case 2:
               pop();   /* call function pop()*/
               break;
            case 3:
               display();   /* call function display()*/
               break;
            default:
               cout<<"Invalid Choice";
               break;
         }
      }while(choice!=4);    

   }

   void push()  //function push
   {

      stack *newptr;
      newptr = new stack;   
      cout<<"\n*********************"<<endl;
      cout<<"        PUSH       ";
      cout<<"\n*********************"<<endl;
      cout<<"Enter the address to insert (&123456): ";
      cin>>newptr->address;
      newptr->next = NULL;
      if(top==NULL){
         top=newptr;    
      }
      else
      {
         newptr->next=top;  
         top=newptr;    

      }
      cout<<"\nThe New Address Has been Inserted"<<endl;
   }

   void pop()//function pop
   {
      stack *cur;
      cur = top;
      cout<<"\n*********************"<<endl;
      cout<<"        POP       ";
      cout<<"\n*********************"<<endl;
      while(cur != NULL) 
      {
         cout<<"\n\t"<<cur->address<<endl; 
         cur = cur->next;
      }
      if(top==NULL){
         cout<<"\nThe stack is Empty"<<endl;
      }
      else{
         cur = top; 
         top = top->next;   
         cout<<endl<<"\nThe address has been popped is "<<cur->address;   
         delete cur;    // delete cur
      }
   }

   void display()   //function display
   {
      stack *cur ;
      cur = top;
      cout<<"\n*********************"<<endl;
      cout<<"\tDISPLAY       ";
      cout<<"\n*********************"<<endl;
      if(top==NULL)
      {
         cout<<"\nNothing to Display\n";
      }
      else
      {
         cout<<"\nThe contents address of Stack\n";
         while(cur!=NULL)   
         {
            cout<<"\n\t"<<cur->address<<endl; 
            cur = cur->next;    
         }
      }
   }

Queue

#include<iostream.h>
#include<string>
   using namespace std;

   struct queue{    //struct with the name of queue                                                 
      string id;
      string location;
      queue *next;
   };
   queue *front, *end;
   void enqueue();
   void dequeue();
   void display();

   void main()
   {        
      int choice;
      front=end=NULL;
      do {
         cout<<"\n\n******************************";
         cout<<"\n       QUEUE MENU        ";
         cout<<"\n******************************"; 
         cout<<"\n\t1.ENQUEUE"<<endl;
         cout<<"\t2.DEQUEUE"<<endl;
         cout<<"\t3.DISPLAY"<<endl;
         cout<<"\t4. EXIT"<<endl;
         cout<<"\n\nEnter your choice: ";
         cin>>choice;
         switch(choice){
            case 1:
               enqueue();   /* call function enqueue()*/
               break;
            case 2:
               dequeue();   /* call function dequeue()*/
               break;
            case 3:
               display();   /* call function display()*/
               break;
            default:
               cout<<"\nInvalid Input. Try again! \n";
               break;
         }
      }while(choice!=4);    

   }

   void enqueue()   //function enqueue
   {

      queue *newptr ;
      newptr = new queue;   
      cout<<"\n*********************"<<endl;
      cout<<"        ENQUEUE       ";
      cout<<"\n*********************"<<endl;
      cout<<"\nEnter The Printer's ID: ";
      cin>>newptr->id;  
      cout<<"Enter The Location: ";
      cin>>newptr->location;    
      newptr->next = NULL;
      if(front == NULL) 
      {
         front =end= newptr;    
      }
      else
      {
         end->next = newptr;    
         end = newptr;  
      }
      cout<<"\nThe New Printer's ID and Location Has been Inserted"<<endl;
   }

   void dequeue()   //function dequeue
   {
      queue *cur ;
      cur= front;
      cout<<"\n*********************"<<endl;
      cout<<"        DEQUEUE       ";
      cout<<"\n*********************"<<endl;
      while(cur!=NULL){ 
         cout<<endl<<"Printer's ID  : "<<cur->id; 
         cout<<endl<<"Location    : "<<cur->location<<endl;
         cur = cur->next;}
      if(front == NULL){
         cout<<"\nThe Queue is Emtpty\n";
      }
      else
      {
         front = front->next;                                                       
         cout<<"The Printer's ID is: "<<cur->id;                                    
         cout<<"\nThe Location is: "<<cur->location;
         delete cur;
      }
   }

   void display()   //function display
   {
      queue *cur ;
      cur = front;                                                                              
      cout<<"\n*********************"<<endl;
      cout<<"        DISPLAY       ";
      cout<<"\n*********************"<<endl;
      if(front == NULL){
         cout<<"\nNothing to Display\n";
      }
      else{
         while(cur!=NULL){
            cout<<endl<<"Printer's ID  : "<<cur->id;  
            cout<<endl<<"Location    : "<<cur->location<<endl;
            cur = cur->next;    
         }
      }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.