C program to implement Double Ended Queue Data Structure
Simple C program to implement Double Ended Queue Data Structure
Code:
#include<stdio.h>#include<conio.h>
int f=0,r=0,q[10],n=10;
void rinsert(int ele)
{
if(r==n && r!=0)
{
printf("Queue overflow");
r=0;
f=0;
}
else
{
q[r]=ele;
r++;
printf("%d is inserted at end of queue",ele);
}
}
void finsert(int ele)
{
if(f==0)
{
printf("Function not allowed");
}
else
{
f--;
q[f]=ele;
printf("%d is inserted at front of queue",ele);
}
}
int rdel()
{
if(r==n)
{
printf("Function not allowed");
}
else if(r==f)
{
printf("Queue underflow");
}
else
{
r--;
printf("%d is deleted",q[r]);
return(q[r]);
}
}
int fdel()
{
if(f==n)
printf("Queue underflow");
else
{
printf("%d is deleted",q[f]);
return(q[f++]);
}
}
void main()
{
int c,ele;
l:
clrscr();
printf("\nEnter 1 for inserting value at front of queue\nEnter 2 for inserting value at end of queue\n3 for deleting value from front of queue\n4 for deleting value from end of queue\n");
scanf("%d",&c);
if(c==1)
{
printf("\nEnter value to insert");
scanf("%d",&ele);
finsert(ele);
}
else if(c==2)
{
printf("\nEnter value to insert");
scanf("%d",&ele);
rinsert(ele);
}
else if(c==3)
{
fdel();
}
else if(c==4)
{
rdel();
}
printf("\n1 for exit \n else continue");
scanf("%d",&c);
if(c!=1)
goto l;
getch();
}
Comments
Post a Comment