#include<stdio.h>
#include<conio.h>
#define max 5
void display();
void input_restricted_dequeue();
void output_restricted_dequeue();
void leftinsertion();
void rightinsertion();
void leftdeletion();
void diplayn();
void rightdeletion();
int left=-1,right=-1,dequeue[max];
void displayn()
{
int i;
printf("\nthe elements are->");
if(left>right)
{
for(i=right;i<=max-1;i++)
printf("%d\t",dequeue[i]);
for(i=0;i<=left;i++)
printf("%d\t",dequeue[i]);
}
else
{
for(i=right;i>=left;i--)
printf("%d\t",dequeue[i]);
}
}
void output_restricted_dequeue()
{
char ch,c,m;
while(1)
{
printf("\nenter i. for insertion at both ends");
printf("\nenter d. for deletion at only one end(left end)");
printf("\nenter e. for exit");
printf("\nenter your choice");
fflush(stdin);
scanf("%c",&ch);
if(ch=='i')
{
while(1)
{
printf("\nenter l. for insertion at left end");
printf("\nenter r. for insertion at right end");
printf("\nenter e. for exit");
printf("\nenter your choice");
fflush(stdin);
scanf("%c",&c);
if(c=='l')
{
leftinsertion();
printf("\nenter y. for display");
printf("\nwant to display the dequeue");
fflush(stdin);
scanf("%c",&m);
if(m=='y')
displayn();
else
printf("\ndonot want to display");
}
else if(c=='r')
{
rightinsertion();
printf("\nenter y. for display");
printf("\nwant to display the dequeue");
fflush(stdin);
scanf("%c",&m);
if(m=='y')
display();
else
printf("\ndonot want to display");
}
else if(c=='e')
goto z;
else
printf("\nyou have entered a wrong choice");
}
z:}
else if(ch=='d')
{
leftdeletion();
printf("\nenter y. for display");
printf("\nwant to display the dequeue");
fflush(stdin);
scanf("%c",&m);
if(m=='y')
display();
else
printf("\ndonot want to display");
}
else if(ch=='e')
goto x;
else
printf("\nyou have entered a wrong choice");
}
x:}
void input_restricted_dequeue()
{
char ch,c,m;
while(1)
{
printf("\nenter i. for insertion at only one end(right end)");
printf("\nenter d. for deletion at both ends");
printf("\nenter e. for exit");
printf("\nenter your choice");
fflush(stdin);
scanf("%c",&ch);
if(ch=='i')
{
rightinsertion();
printf("\nenter y. for display");
printf("\nwant to display the dequeue");
fflush(stdin);
scanf("%c",&m);
if(m=='y')
display();
else
printf("\ndonot want to display");
}
else if(ch=='d')
{
while(1)
{
printf("\nenter l. for the left deletion");
printf("\nenter r. for the right deletion");
printf("\nenter e. for exit");
printf("\nenter your choice");
fflush(stdin);
scanf("%c",&c);
if(c=='l')
{
leftdeletion();
printf("\nenter y. for display");
printf("\nwant to display the dequeue");
fflush(stdin);
scanf("%c",&m);
if(m=='y')
display();
else
printf("\ndonot want to display");
}
else if(c=='r')
{
rightdeletion();
printf("\nenter y. for display");
printf("\nwant to display the dequeue");
fflush(stdin);
scanf("%c",&m);
if(m=='y')
displayn();
else
printf("\ndonot want to display");
}
else if(c=='e')
goto z;
else
printf("\nyou have entered a wrong choice");
}
z:}
else if(ch=='e')
goto x;
else
printf("\nyou have entered a wrong choice");
}
x:}
void rightinsertion()
{
int n;
if(right==max-1 && left==0 || right==left-1)
printf("\ndequeue is overflow");
else
{
printf("\nenter the value to be queued");
fflush(stdin);
scanf("%d",&n);
if(right==-1)
left=0;
if(right==max-1)
{
right=0;
dequeue[right]=n;
}
else
{
right++;
dequeue[right]=n;
}
}
}
void leftdeletion()
{
int s;
if(left==-1)
printf("\ndequeue is underflow");
else
{
if(left==right)
{
s=dequeue[left];
printf("\ndeleted element is=%d",s);
left=-1;
right=-1;
}
else
{
s=dequeue[left];
if(left==max-1)
left=0;
else
left++;
}
}
}
void rightdeletion()
{
int s;
if(right==-1)
printf("\nqueue is underflow");
else
{
if(left==right)
{
s=dequeue[right];
printf("\ndeleted element is %d",s);
left=-1;
right=-1;
}
else
{
s=dequeue[right];
printf("\ndeleted element is %d",s);
if(right==0)
right=max-1;
else
right--;
}
}
}
void leftinsertion()
{
int n;
if(right==max-1 && left==0 || right==left-1)
printf("\ndequeue is overflow");
else
{
printf("\nenter the value to be queued");
scanf("%d",&n);
if(left==-1)
{
right=max-1;
left=max-1;
}
else
{
if(left==0)
left=max-1;
else
left--;
}
dequeue[left]=n;
}
}
void display()
{
int i;
printf("\nthe elements are->");
if(left>right)
{
for(i=left;i<=max-1;i++)
printf("%d\t",dequeue[i]);
for(i=0;i<=right;i++)
printf("%d\t",dequeue[i]);
}
else
{
for(i=left;i<=right;i++)
printf("%d\t",dequeue[i]);
}
}

void main()
{
char ch;
clrscr();
while(1)
{
printf("\nenter o. for output restricted dequeue");
printf("\nenter i. for input restricted dequeue");
printf("\nenter e. for exit");
printf("\nenter your choice");
fflush(stdin);
scanf("%c",&ch);
switch(ch)
{
case 'i':
input_restricted_dequeue();
case 'o':
output_restricted_dequeue();
case 'e':
exit(0);
default:
printf("\nyou have entered a wrong choice");
}
}
}