#include <iostream>
using namespace std;
class deque{
private:
int F,B,DQ[5];
public:
deque()
{
F=-1;
B=-1;
}
void insert_front(int);
void insert_back(int);
void del_front(void);
void del_back(void);
void print_deque(void);
};
int main()
{
deque obj;
int val,opt;
while (true)
{
cout<<"1: insert in the front of deque"<<endl;
cout<<"2: insert in the back of deque"<<endl;
cout<<"3: Delete in the front of deque"<<endl;
cout<<"4: Delete in the back of deque"<<endl;
cout<<"5: Exit Programm"<<endl;
cin>>opt;
switch (opt)
{
case 1:
cout<<"Enter value for insertion"<<endl;
cin>>val;
obj.insert_front(val);
obj.print_deque();
break;
case 2:
cout<<"Enter value for insertion"<<endl;
cin>>val;
obj.insert_back(val);
obj.print_deque();
break;
case 3:
obj.del_front();
obj.print_deque();
break;
case 4:
obj.del_back();
obj.print_deque();
break;
case 5:
exit(0);
break;
default:
cout<<"invalid input"<<endl;
break;
}
}
return 0;
}
void deque::insert_front(int n){
if(F==0 && B==4){
cout<<"Queue is full"<<endl;
return;
}
if(F==-1 && B==-1){
F=B=0;
DQ[F]=n;
}
else if(F>0){
F--;
DQ[F]=n;
}
else{
cout<<"There is no space in front side"<<endl;
}
}
void deque::insert_back(int n){
if(F==0 && B==4){
cout<<"Queue is full"<<endl;
return;
}
if(F==-1 && B==-1)
{
F=B=0;
DQ[B]=n;
}
else if(B<4){
B++;
DQ[B]=n;
}
else{
cout<<"There is no space in back side"<<endl;
}
}
void deque::del_front(){
if(F==-1 && B==-1)
{
cout<<"Queue is empty"<<endl;
return;
}
else{
DQ[F]=NULL;
}
if(F==B)
{
F=B=-1;
}
else if(F==4){
F--;
}
else{
F++;
}
}
void deque::del_back(){
if(F==-1 && B==-1){
cout<<"Queue is empty"<<endl;
return;
}
else{
DQ[B]=NULL;
}
if(F==B){
F=B=-1;
}
else{
B--;
}
}
void deque::print_deque(){
cout<<"Deque after operations"<<endl;
if(F==-1){
cout<<"Queue is empty"<<endl;
return;
}
for(int i=F;i<=B;i++){
cout<<DQ[i]<<"\t";
}
cout<<endl;
}