C Programming

Double Ended Linear Queue – Dequeue

Elements can be added and removed from the Queue from both ends. This general data class has some possible sub-types:

  • An input-restricted deque is one where deletion can be made from both ends, but input can only be made at one end.
  • An output-restricted deque is one where input can be made at both ends, but output can be made from one end only.

Languge : C

[sourcecode language='c']
#include
#include
#include # define MAX 50

int Q[MAX],R=-1,F=-1;
int ele;

void inprest();
void outprest();
void insertion();
void frontinsert();
void rareinsert();
int deletion();
int frontdelete();
int raredelete();
void display();

void main()
{
char c;
do
{
clrscr();
printf(“\n\t\t!*!*!*!*!*!*!*!*!*! QUEUE !*!*!*!*!*!*!*!*!*!”);
printf(“\n\n\n\t\t\t\t MAIN MENU”);
printf(“\n\t\t\t\t~~~~~~~~~~~”);
printf(“\n\n\n\t\t\t1.INPUT RESTRICT”);
printf(“\n\n\n\t\t\t2.OUTPUT RESTRICT”);
printf(“\n\n\n\t\t\t3.DISPLAY”);
printf(“\n\n\n\t\t\t4.EXIT”);
printf(“\n\n\n\t\t- Enter your choice : “);
c=getche();
clrscr();
switch(c)
{
case ’1′:
inprest();
break;
case ’2′:
outprest();
break;
case ’3′:
printf(“\n\n\t\t\t\t DISPLAY OF QUEUE”);
printf(“\n\t\t\t\t*****************\n\n”);
display();
printf(“\n\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’4′:
break;
default:
printf(“\n\n\n\n\n\t\tWRONG CHOICE !!!”);
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
}
}while(c!=’4′);
}
void inprest()
{
char ch;
do
{
clrscr();
printf(“\n\n\t\t\t\t INPUT RESTRICT QUEUE”);
printf(“\n\t\t\t\t**********************”);
printf(“\n\n\n\t\t\t\t Input Restrict Menu “);
printf(“\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~”);
printf(“\n\n\t\t\t\t1.Insertion”);
printf(“\n\n\t\t\t\t2.Deletion”);
printf(“\n\n\t\t\t\t3.Display”);
printf(“\n\n\t\t\t\t4.Exit”);
printf(“\n\n\t\tEnter your choice : “);
ch=getche();
clrscr();
switch(ch)
{
case ’1′:
rareinsert();
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’2′:
deletion();
break;
case ’3′:
printf(“\n\n\t\t\t\t DISPLAY OF QUEUE”);
printf(“\n\t\t\t\t——————\n\n”);
display();
printf(“\n\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’4′:
break;
default:
printf(“\n\n\n\n\n\t\tWRONG CHOICE !!!”);
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
}
}while(ch!=’4′);
}
void outprest()
{
char cho;
do
{
clrscr();
printf(“\n\n\t\t\t\t OUTPUT RESTRICT QUEUE”);
printf(“\n\t\t\t\t***********************”);
printf(“\n\n\n\t\t\t\t Output Restrict Menu “);
printf(“\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~~”);
printf(“\n\n\t\t\t\t1.Insertion”);
printf(“\n\n\t\t\t\t2.Deletion”);
printf(“\n\n\t\t\t\t3.Display”);
printf(“\n\n\t\t\t\t4.Exit”);
printf(“\n\n\t\tEnter your choice : “);
cho=getche();
clrscr();
switch(cho)
{
case ’1′:
insertion();
break;
case ’2′:
frontdelete();
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’3′:
printf(“\n\n\t\t\t\t Display of Queue”);
printf(“\n\t\t\t\t=================\n\n”);
display();
printf(“\n\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’4′:
break;
default:
printf(“\n\n\t\tWRONG CHOICE !!!”);
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
}
}while(cho!=’4′);
}
void insertion()
{
char choi;
do
{
clrscr();
printf(“\n\n\t\t\t INSERTION OF ELEMENT IN QUEUE”);
printf(“\n\t\t\t—————————-”);
printf(“\n\n\n\t\t\t\t Insertion Menu”);
printf(“\n\t\t\t\t~~~~~~~~~~~”);
printf(“\n\n\t\t\t\t1.From Front “);
printf(“\n\n\t\t\t\t2.From Rare”);
printf(“\n\n\t\t\t\t3.Display”);
printf(“\n\n\t\t\t\t4.Exit”);
printf(“\n\n\t\tEnter your choice : “);
choi=getche();
clrscr();
switch(choi)
{
case ’1′:
frontinsert();
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’2′:
rareinsert();
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’3′:
printf(“\n\n\t\t\t\tDISPLAY OF QUEUE”);
printf(“\n\t\t\t\t+++++++++++++++++\n\n”);
display();
printf(“\n\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’4′:
break;
default:
printf(“\n\n\t\tWRONG CHOICE !!!”);
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
}
}while(choi!=’4′);
}
int deletion()
{
char chois;
do
{
clrscr();
printf(“\n\n\t\t\t\t DELETION OF ELEMENT FROM QUEUE”);
printf(“\n\t\t\t\t——————————”);
printf(“\n\n\n\t\t\t\t Deletion Menu”);
printf(“\n\t\t\t\t~~~~~~~~~~~”);
printf(“\n\n\t\t\t\t1.From Front”);
printf(“\n\n\t\t\t\t2.From Rare”);
printf(“\n\n\t\t\t\t3.Display”);
printf(“\n\n\t\t\t\t4.Exit”);
printf(“\n\n\t\tEnter your choice : “);
chois=getche();
clrscr();
switch(chois)
{
case ’1′:
frontdelete();
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’2′:
raredelete();
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’3′:
printf(“\n\n\t\t\t\tDISPLAY OF QUEUE”);
printf(“\n\t\t\t\t+++++++++++++++++\n\n”);
display();
printf(“\n\n\n\n\n\n\t\tPress any key to continue……”);
getch();
break;
case ’4′:
break;
default:
printf(“\n\n\t\tWRONG CHOICE !!!”);
printf(“\n\n\n\n\n\t\tPress any key to continue……”);
getch();
}
}while(chois!=’4′);
}
void frontinsert()
{
int i;
printf(“\n\n\t\t\t INSERTION OF ELEMENT IN QUEUE”);
printf(“\n\t\t\t——————————-”);
printf(“\n\n\n\t\t\t@ Insertion from Front of Queue”);
printf(“\n\t\t\t*********************************”);
if(R==MAX-1)
{
printf(“\n\n\n\n\t\tQueue is FULL, NO more insertion is possible.”);
printf(“\n\n\t\t\tOVERFLOW !!!”);
}
else
{
printf(“\n\n\n\n\t\tEnter the element you want to insert in the Queue : “);
scanf(“%d”,&ele);
if(F==-1)
{
F=0;
}
R++;
for(i=R;i>=F;i–)
{
Q[i+1]=Q[i];
}
Q[F]=ele;
}
}
void rareinsert()
{
printf(“\n\n\t\t\t INSERTION OF ELEMENT IN QUEUE”);
printf(“\n\t\t\t——————————-”);
printf(“\n\n\n\t\t\t@ Insertion from Rare or End of the Queue “);
printf(“\n\t\t\t+++++++++++++++++++++++++++++++++++++++++++”);
if(R==MAX-1)
{
printf(“\n\n\n\n\t\tQueue is FULL, NO more insertion is possible.”);
printf(“\n\n\t\t\tOVERFLOW !!!”);
}
else
{
R++;
printf(“\n\n\n\n\t\tEnter the element you want to insert in the Queue : “);
scanf(“%d”,&ele);
Q[R]=ele;
if(F==-1)
{
F=0;
}
}
}
int frontdelete()
{
printf(“\n\n\t\t\t\t DELETION OF ELEMENT FROM QUEUE”);
printf(“\n\t\t\t\t——————————”);
printf(“\n\n\t\t\t@ Deletion from Front of the Queue”);
printf(“\n\t\t\t**********************************”);
if(F>R || F==-1)
{
printf(“\n\n\n\t\t\tThe Queue is EMPTY.”);
printf(“\n\n\t\t\tUNDERFLOW !!!”);
}
else
{
ele=Q[F];
F++;
printf(“\n\n\n\t\t\tThe deleted element is : %d”,ele);
return(ele);
}
}
int raredelete()
{
printf(“\n\n\t\t\t\t DELETION OF ELEMENT FROM QUEUE”);
printf(“\n\t\t\t\t——————————”);
printf(“\n\n\n\t\t\t@ Deletion from Rare or End of the Queue”);
printf(“\n\t\t\t\t++++++++++++++++++++++++++++++++++++++++”);
if(R {
printf("\n\n\n\t\t\tThe Queue is EMPTY.");
printf("\n\n\t\t\tUNDERFLOW !!!");
}
else
{
ele=Q[R];
R--;
printf("\n\n\n\t\tThe deleted Element is %d ",ele);
return(ele);
}
}
void display()
{
int i;
if(F==-1 || F>R)
{
printf(“\n\n\n\t\t\tThe Queue is EMPTY.”);
}
else
{
for(i=F;i<=R;i++)
{
printf(“\t%d”,Q[i]);
}
}
}
[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal