#include<iostream>
using namespace std;
int a,queue[5],front=-1,rear=-1,num;
void enq();
void deq();
int main()
{
cin>>a;
while(a!=0)
{
switch(a)
{
case 1:
cin>>num;
if(front==-1 && rear==-1)
{
front=0;
rear=0;
}
else
rear++;
queue[rear]=num;
break;
case 2:
if(front==-1 || front>rear)
cout<<"Underflow";
else
front++;
break;
case 3:
for(int i=front;i<=rear;i++)
{
cout<<queue[i]<<"->";
}
cout<<endl;
break;
}
if(front>rear)
{
cout<<"Underflow";
exit(0);
}
cin>>a;
}
return 0;
}
using namespace std;
int a,queue[5],front=-1,rear=-1,num;
void enq();
void deq();
int main()
{
cin>>a;
while(a!=0)
{
switch(a)
{
case 1:
cin>>num;
if(front==-1 && rear==-1)
{
front=0;
rear=0;
}
else
rear++;
queue[rear]=num;
break;
case 2:
if(front==-1 || front>rear)
cout<<"Underflow";
else
front++;
break;
case 3:
for(int i=front;i<=rear;i++)
{
cout<<queue[i]<<"->";
}
cout<<endl;
break;
}
if(front>rear)
{
cout<<"Underflow";
exit(0);
}
cin>>a;
}
return 0;
}
No comments:
Post a Comment