C program on double ended queue(deletion and insertion).

Here we are going to create 5 functions (insertion at rear end ,deletion at rear end and insertion at front end ,deletion at front end and last one for display element of double ended queue ). 

#include<stdio.h>
#define max 5
int de_queue[max];
int front=-1;
int rear=-1;
void rear_insert()
{
int element;
if(rear==max1)
printf(“overflow conditionn”);
else
{
if(front==-1)
front=0;
printf(“Enter a elementn”);
scanf(“%d”,&element);
rear=rear+1;
de_queue[rear]=element;
}
}
void front_insert()
{
int element;
if(front==0||front==-1)
printf(“overflow conditionn”);
else
{
printf(“Enter a elementn”);
scanf(“%d”,&element);
front=front1;
de_queue[front]=element;
}
}
void rear_delete()
{
int element;
if(rear==-1||front>rear)
printf(“underflown”);
else
{
element=de_queue[rear];
rear=rear1;
printf(“%d is deletedn”,element);
}
}
void front_delete()
{
int element;
if(front==-1||front>rear)
printf(“underflown”);
else
{
element=de_queue[front];
printf(“%d is deletedn”,element);
front=front+1;
}
}
void display()
{
int i;
if(front==-1||rear==-1||front>rear)
printf(“queue is underflown”);
else
{
for(i=front;i<=rear;i++)
printf(“%d “,de_queue[i]);
printf(“n”);
}
}
int main()
{
int ch;
printf(“1. Insertion at rear endn”);
printf(“2. Deletion at rear endn”);
printf(“3. Insertion at front endn”);
printf(“4. Deletion at front endn”);
printf(“5. Displayn”);
printf(“6.exitn”);
while(1)
{
printf(“Enter your choicen”);
scanf(“%d”,&ch);
switch(ch)
{
case 1: rear_insert();
break;
case 2: rear_delete();
break;
case 3: front_insert();
break;
case 4: front_delete();
break;
case 5: display();
break;
case 6: exit(0);
default: printf(“Wrong keyn”);
}
}
return 0;
}

2 thoughts on “C program on double ended queue(deletion and insertion).

Leave a Reply

Your email address will not be published.