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;
}