2016-08-09 18:20:07 +08:00
|
|
|
#include<iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int queue[10];
|
|
|
|
int front=0;
|
|
|
|
int rear=0;
|
|
|
|
|
2016-08-09 19:10:41 +08:00
|
|
|
void Enque(int x)
|
2016-08-09 18:20:07 +08:00
|
|
|
{
|
|
|
|
if(rear==10)
|
|
|
|
{
|
|
|
|
cout<<"\nOverflow";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
queue[rear++]=x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 19:10:41 +08:00
|
|
|
void Deque()
|
2016-08-09 18:20:07 +08:00
|
|
|
{
|
|
|
|
if (front==rear)
|
|
|
|
{
|
|
|
|
cout<<"\nUnderflow";
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout<<"\n"<<queue[front++]<<" deleted";
|
|
|
|
for (int i = front; i < rear; i++)
|
|
|
|
{
|
|
|
|
queue[i-front]=queue[i];
|
|
|
|
}
|
|
|
|
rear=rear-front;
|
|
|
|
front=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void show()
|
|
|
|
{
|
|
|
|
for (int i = front; i < rear; i++)
|
|
|
|
{
|
|
|
|
cout<<queue[i]<<"\t";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int ch, x;
|
|
|
|
do
|
|
|
|
{
|
2016-08-09 19:10:41 +08:00
|
|
|
cout<<"\n1. Enque";
|
|
|
|
cout<<"\n2. Deque";
|
2016-08-09 18:20:07 +08:00
|
|
|
cout<<"\n3. Print";
|
|
|
|
cout<<"\nEnter Your Choice : ";
|
|
|
|
cin>>ch;
|
|
|
|
if (ch==1)
|
|
|
|
{
|
|
|
|
cout<<"\nInsert : ";
|
|
|
|
cin>>x;
|
2016-08-09 19:10:41 +08:00
|
|
|
Enque(x);
|
2016-08-09 18:20:07 +08:00
|
|
|
}
|
|
|
|
else if (ch==2)
|
|
|
|
{
|
2016-08-09 19:10:41 +08:00
|
|
|
Deque();
|
2016-08-09 18:20:07 +08:00
|
|
|
}
|
|
|
|
else if (ch==3)
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(ch!=0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|