#include<iostream>
using namespace std;
int f=0,r=0,q[10];
int enqueue(int val)
{
if(r==10)
cout<<"\nQueue overflows";
else
{
q[++r]=val;
if(f==0)
f=1;
}
return q[r];
}
void dequeue()
{
if(f==0)
cout<<"\nQueue underflow";
else
{
if(f==r)
f=r=0;
else
f++;
}
}
void display()
{
for(int i=f;i<=r;i++)
cout<<q[i]<<" ";
}
int main()
{
int choice,val;
while(1)
{
cout<<"\n1.Enqueue 2.Dequeue 3.Display 4.Exit\nEnter your choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter value:";cin>>val;
enqueue(val);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
return 0;
break;
default:
cout<<"\nCheck your input";
}
}
return 0;
}
using namespace std;
int f=0,r=0,q[10];
int enqueue(int val)
{
if(r==10)
cout<<"\nQueue overflows";
else
{
q[++r]=val;
if(f==0)
f=1;
}
return q[r];
}
void dequeue()
{
if(f==0)
cout<<"\nQueue underflow";
else
{
if(f==r)
f=r=0;
else
f++;
}
}
void display()
{
for(int i=f;i<=r;i++)
cout<<q[i]<<" ";
}
int main()
{
int choice,val;
while(1)
{
cout<<"\n1.Enqueue 2.Dequeue 3.Display 4.Exit\nEnter your choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter value:";cin>>val;
enqueue(val);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
return 0;
break;
default:
cout<<"\nCheck your input";
}
}
return 0;
}
No comments:
Post a Comment