#include<iostream.h>
#include<conio.h>
#include<process.h>
const int Size=100;
void insert(int Q[],int &f,int &r,int d)
{
if(r==Size-1)
cout<<"Queue Full";
else
{
if(r==-1)
f=r=0;
else
r=r+1;
Q[r]=d;
}
}
void del(int Q[],int &f,int &r)
{
if(f==-1)
cout<<"Queue Empty";
else
{
cout<<"The element to be deleted is"<<Q[f];
if(f==r)
f=r=-1;
else
f=f+1;
}
}
void display(int Q[],int f,int r)
{
if(f==-1)
cout<<"Queue Empty";
else
{
for(int i=f;i<=r;i++)
cout<<Q[i]<<" ";
}
}
void main()
{
clrscr();
int Q[Size],front=-1,rear=-1,data,option;
while(1)
{
cout<<"\n 1.Insert \n 2.Delete \n 3.Display\n 4.Exit\n Enter your Option";
cin>>option;
switch(option)
{
case 1:
cout<<"\nEnter the element to be pushed";
cin>>data;
insert(Q,front,rear,data);
break;
case 2:
del(Q,front,rear);
break;
case 3:
display(Q,front,rear);
break;
case 4:
exit(0);
}
}
}
#include<conio.h>
#include<process.h>
const int Size=100;
void insert(int Q[],int &f,int &r,int d)
{
if(r==Size-1)
cout<<"Queue Full";
else
{
if(r==-1)
f=r=0;
else
r=r+1;
Q[r]=d;
}
}
void del(int Q[],int &f,int &r)
{
if(f==-1)
cout<<"Queue Empty";
else
{
cout<<"The element to be deleted is"<<Q[f];
if(f==r)
f=r=-1;
else
f=f+1;
}
}
void display(int Q[],int f,int r)
{
if(f==-1)
cout<<"Queue Empty";
else
{
for(int i=f;i<=r;i++)
cout<<Q[i]<<" ";
}
}
void main()
{
clrscr();
int Q[Size],front=-1,rear=-1,data,option;
while(1)
{
cout<<"\n 1.Insert \n 2.Delete \n 3.Display\n 4.Exit\n Enter your Option";
cin>>option;
switch(option)
{
case 1:
cout<<"\nEnter the element to be pushed";
cin>>data;
insert(Q,front,rear,data);
break;
case 2:
del(Q,front,rear);
break;
case 3:
display(Q,front,rear);
break;
case 4:
exit(0);
}
}
}