2016-08-09 18:20:07 +08:00
|
|
|
#include<iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int queue[10];
|
|
|
|
int front=0;
|
|
|
|
int rear=0;
|
|
|
|
int count=0;
|
|
|
|
|
2016-08-09 19:10:41 +08:00
|
|
|
void Enque(int x)
|
2016-08-09 18:20:07 +08:00
|
|
|
{
|
|
|
|
if(count==10)
|
|
|
|
{
|
|
|
|
cout<<"\nOverflow";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
queue[rear]=x;
|
|
|
|
rear=(rear+1)%10;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
front=(front+1)%10;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void show()
|
|
|
|
{
|
|
|
|
for (int i = 0; i<count; i++)
|
|
|
|
{
|
|
|
|
cout<<queue[(i+front)%10]<<"\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;
|
|
|
|
}
|
|
|
|
|