Write C++ program using STL for implementation of queue using SLL.

 Write C++ program using STL for implementation of queue using SLL.


#include<iostream>

#include<queue>


using namespace std;

OUTPUT FOR THE PROGRAM

int main()

{

   int data,i,n;

   int ch; 

   char ans;

   

   queue<int>q;

   do

   {

      cout<<"\nQueue Using STL";

      cout<<"\n1.Insert";

      cout<<"\n2.Delete";

      cout<<"\n3.Size ";

      cout<<"\n4.Display Front element";

      cout<<"\n5.Dispaly Rear element";

      cout<<"\n6.Display All Element";

      cout<<"\n\nEnter your choice : ";

      cin>>ch;

      switch(ch)

      {

case 1:

              if(q.empty())

      {

                  cout<<"\nHow many elements do you want to insert : ";

            cin>>n;

          for(i=0;i<n;i++)

                  {

     cout<<"\nEnter "<<i+1<<" Element :";

     cin>>data;

     q.push(data);

          }

      }

      else

      {

cout<<"\nQueue is Full";

      }

      break;

   

         case 2 :

            if(!q.empty())

            {

                cout<<"\nDeleted element is : "<<q.front();

                q.pop();

            }

            else

            {

                cout<<"\nQueue is Empty...!!!";

            }

              break;

   

case 3 :

     if(!q.empty())

           {

               cout<<"\nSize of Queue is : "<<q.size();     

           }

           else

           {

                 cout<<"\nQueue is Empty...!!!";

           }

           break;

     

       case 4:

            if(!q.empty())

            { 

              cout<<"\nFront element of queue is : "<<q.front();

            }

            else

            {

                cout<<"\nQueue is Empty...!!!";

            }

          break;

    

       case 5:

            if(!q.empty())

          { 

                cout<<"\n Rear element is: "<<q.back();

            }

            else

          {

              cout<<"\nQueue is Empty...!!!";

          }

          break;

     

      case 6:

           cout<<"\nQueue elements are:";

           while(!q.empty())

         { 

            cout<<" "<<q.front();

              q.pop();

           }

           break;

          

      default :

          cout<<"\nPlease Enter valid choice...!!!";

          break;

         

     }

      cout<<"\nDo you want to continue(y/n) : ";

      cin>>ans;

  }

   while(ans=='y'||ans=='Y');

   return 0;

}


                                                  ********** OUTPUT ************

/*       
student@IOE-HWLAB:~$ g++ 9.queue_STL.cpp -o a
student@IOE-HWLAB:~$ ./a

Queue Using STL
1.Insert
2.Delete
3.Size 
4.Display Front element
5.Dispaly Rear element
6.Display All Element

Enter your choice : 1

How many elements do you want to insert : 5

Enter 1 Element :1

Enter 2 Element :2

Enter 3 Element :3

Enter 4 Element :4

Enter 5 Element :5

Do you want to continue(y/n) : y

Queue Using STL
1.Insert
2.Delete
3.Size 
4.Display Front element
5.Dispaly Rear element
6.Display All Element

Enter your choice : 2

Deleted element is : 1
Do you want to continue(y/n) : y

Queue Using STL
1.Insert
2.Delete
3.Size 
4.Display Front element
5.Dispaly Rear element
6.Display All Element

Enter your choice : 3

Size of Queue is : 4
Do you want to continue(y/n) : y

Queue Using STL
1.Insert
2.Delete
3.Size 
4.Display Front element
5.Dispaly Rear element
6.Display All Element

Enter your choice : 4

Front element of queue is : 2
Do you want to continue(y/n) : y

Queue Using STL
1.Insert
2.Delete
3.Size 
4.Display Front element
5.Dispaly Rear element
6.Display All Element

Enter your choice : 5

 Rear element is: 5
Do you want to continue(y/n) : y

Queue Using STL
1.Insert
2.Delete
3.Size 
4.Display Front element
5.Dispaly Rear element
6.Display All Element

Enter your choice : 6

Queue elements are: 2 3 4 5
Do you want to continue(y/n) : n

*/

For more such posts click the link:-http://svencrai.com/G8W

Comments

Popular posts from this blog

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message ?Required copies not in stock? is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

Write C++ program for storing appointment schedule for day. Appointments are booked randomly using linked list. Set start and end time and min and max duration for visit slot. Write functions for- a)Display free slots b)Book appointment c)Cancel appointment ( check validity, time bounds, availability etc) d)Sort list based on time e)Sort list based on time using pointer manipulation

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.