34)Write a menu driven program using C for Static implementation of circular queue for characters. -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()
{
char 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(“%c”,&n);
n=getchar();
n=getchar();
a[rear]=n;
}
else
{
rear++;
printf(“\nEnter the Element”);
n=getchar();
n=getchar();
//scanf(“%c”,&n);
a[rear]=n;
}
}
}
}
void del()
{
if(front==-1)
{
printf(“\nQ is Empty”);
}
else
{
printf(“Deleted Element is %c”, 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(“%c->”,a[i]);
}
}
else
{
for(i=front;i<=MAX-1;i++)
{
printf(“%c->”,a[i]);
}
for(i=0;i<=rear;i++)
{
printf(“%c->”,a[i]);
}
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s