/*write a menu driven program using c for circular Queue on character.
the menu include
-Insert
-delete
-display
-exit
*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define max 3
char q[max],item;
int front=-1,rare=0;
void insert();
void delete();
void display();
void main()
{
int choice;
char ch='y';
clrscr();
do
{
printf("\n1:insert\n");
printf("\n2:delete\n");
printf("\n3:display\n");
printf("\n4:exit\n");
printf("\nenter your choice:-");
scanf("\n%d",&choice);
switch(choice)
{
case 1:insert();
break;
case 2:delete();
break;
case 3:display();
break;
case 4:exit();
default:printf("\nyou entered wrong choice");
}
printf("\ndo you want to continue(Y|N):-");
scanf("%s",&ch);
}while(ch=='y'||ch=='Y');
getch();
}
void insert()
{
if(front==(rare+1)%max)
{
printf("\nQueue is full");
return;
}
else
{
printf("\nenter the character:-");
flushall();
scanf("%c",&item);
if(front==-1)
front=rare=0;
else
rare=(rare+1)%max;
q[rare]=item;
}
}
void delete()
{
if(front==-1)
{
printf("\nQueue is empty");
return;
}
else
{
item=q[front];
printf("\nthe deleted character is:-%c",item);
if(front==rare)
front=rare=-1;
else
front=(front+1)%max;
}
}
void display()
{
int i;
if(front==-1)
{
printf("\nQueue is empty");
return;
}
else
{
printf("\nelement in Queue are:\n");
for(i=front;i<=rare;i++)
printf("%c\t",q[i]);
}
if(front>rare)
{
for(i=front;i<max;i++)
printf("%c\t",q[i]);
for(i=0;i<=rare;i++)
printf("%c\t",q[i]);
}
}
/*
1:insert
2:delete
3:display
4:exit
enter your choice:-2
Queue is empty
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-3
Queue is empty
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-9
you entered wrong choice
do you want to continue(Y|N):-n
*/
/*
1:insert
2:delete
3:display
4:exit
enter your choice:-1
enter the character:-a
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
enter the character:-b
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
enter the character:-c
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
Queue is full
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
enter the character:-d
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-3
element in Queue are:
c d
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
enter the character:-d
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-3
element in Queue are:
c d d
do you want to continue(Y|N):-n
*/
No comments:
Post a Comment