Queue example for remove value with front fixed

#include<iostream>
#include<conio.h>
#define MAX 100
using namespace std;
class queue
{
int data[MAX];
int rear,front;

public:
//default constructor
queue()
{
rear=-1;
front=0;
}
int full()
{
return(rear==5-1);
}
int empty()
{
return(rear==-1 && front==0);
}
void addqueue(int x)
{
cout<<"rear= "<<rear<<"....front="<<front<<endl;
if(!full())
{
rear++;
data[rear]=x;
}
else
{
cout<<"full\n";
}
}

int removequeueFrontFixed()
{
int x=0;            
cout<<"front="<<front<<"....rear="<<rear<<endl;
if(!empty())
{
x=data[front];
for(int i=front;i<rear;i++)
{
data[i]=data[i+1];
}
rear--;
}
else
{
cout<<"empty\n";
}
return x;

}
int count()
{
return((rear-front)+1);
}

int removequeueRearFixed()
{
int x=0;
cout<<"rear="<<rear<<"....front="<<front<<endl;
if(!empty())
{
x=data[front];
front++;
}
else
{
cout<<"empty";
}
return x;

}
};


int main()
{
queue q1;
int ch,cnt,x;
do{
cout<<"enter\n1.add value in queue\n2.remove value with front fixed\n3.remove value with rear fixed\n4.count\n";
cin>>ch;
if(ch==1)
{
cout<<"add value\n";
for(int i=0;i<5;i++)
{
cin>>x;
q1.addqueue(x);
}
}
else if(ch==2)
{
cout<<"delete queue\n";
for(int i=0;i<5;i++)
{
cout<<q1.removequeueFrontFixed()<<endl;
}

}
else if(ch==3)
{
     cout<<"remove queue";
     for(int i=0;i<5;i++)
     {
     
cout<<q1.removequeueRearFixed()<<endl;
}
}
else if(ch==4)
{
cout<<q1.count()<<endl;
}
cout<<"do u want to continue then press 5\n";
cin>>cnt;}
while(cnt==5);

getch();
}

Leave a Reply