using namespace std;
int Q[10];
int size=10;
int count=0;
int rear=0;
int front=0;
void enQ(int element)
{
if(count==size)
{
cout<<"Queue Overflow"<<endl;
}
else
{
Q[rear]=element;
rear=(rear+1)%size;
count++;
}
}
void DeQ()
{
if(count==0)
{
cout<<"Under Flow"<<endl;
}
else
{
Q[front]=0;
front=(front+1)%size;
count--;
}
}
bool isempty()
{
if(count==0)
{
return true;
}
}
int main()
{
int element;
int e;
if(isempty()==true)
{
cout<<"Queue is empty"<<endl;
}
/*************Enqueue*************/
do
{
cout<<"Enter element in queue:"<<endl;
cin>>element;
enQ(element);
cout<<"Do you want enqueue again?" <<endl;
cin>>e;
}while(e==1);
/************display*************/
cout<<"After inserting value in circular queue"<<endl;
for(int i=front;i<=count;i++)
{
cout<<Q[i]<<" ";
}
/***************deletion***************/
int d;
cout<<"Do you want to delete from the queue(1=y): "<<endl;
cin>>d;
if(d==1)
{
int c;
do
{
DeQ();
cout<<"DO you want to enqueue again?(1=y)"<<endl;
cin>>c;
}while(c==1);
}
/************display*************/
cout<<"After Dequeuing"<<endl;
for(int i=front;i<=count;i++)
{
cout<<Q[i]<<" ";
}
return 0;
}
0 comments:
Post a Comment