56)Write a menu driven program in C for static implementation of circular queue for integers -Insert -Delect -Display -Exit


#include<stdio.h>
#include<conio.h>
#define MAX 3
int a[MAX];
int front=-1;
int rear=-1;
void insert();
void del();
void disp();
void main()
{
int ch;
clrscr();
do
{
printf(“\nMenu \n”);
printf(“\n1.INSERT”);
printf(“\n2.del”);
printf(“\n3.disp”);
printf(“\n4.exit”);
printf(“\nEnter ur choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
disp();
break;
case 4:
exit(0);
}
}
while(ch!=4);
getch();
}
void insert()
{
int n;
if((front==0 && rear==MAX-1)||(front==rear+1 && front>0))
{
printf(“Q is Full”);
}
else
{
if(front==-1)
{
front=0;
}
else
{
if(rear==MAX-1 && front>0)
{
rear=0;
printf(“\n\nENTER THE DATA”);
scanf(“%d”,&n);
a[rear]=n;
}
else
{
rear++;
printf(“\nEnter the Element”);
scanf(“%d”,&n);
a[rear]=n;
}
}
}
}
void del()
{
if(front==-1)
{
printf(“\nQ is Empty”);
}
else
{
printf(“Deleted Element is %d”, a[front]);
if(front==rear)
{
front=-1;
rear=-1;
}
else
{
if(front==MAX-1)
{
front=0;
}
else
{
front++;
}
}
}
}
void disp()
{
int i;
if(front==-1)
{
printf(“\nQ is Empty”);
}
else
{
if(front<=rear)
{
for(i=front;i<=rear;i++)
{
printf(“%d->”,a[i]);
}
}
else
{

for(i=front;i<=MAX-1;i++)
{
printf(“%d->”,a[i]);
}
for(i=0;i<=rear;i++)
{
printf(“%d->”,a[i]);
}
}
}
}

Leave a comment