/*write a menu driven program using c fro static implementation of
Queue. the menu includes:-
-insert
-delete
-display
-exit
*/
#include<stdio.h>
#include<conio.h>
#define size 3
int front=0,rare=0,q[size];
void insert();
void del();
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:del();
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(rare<size)
{
printf("\nenter the element:-");
scanf("%d",&q[rare]);
rare=rare+1;
}
else
printf("\nQ is full");
}
void del()
{
if(front==rare)
printf("\nQ is empty");
else
{
printf("\nthe deleted element is:-%d",q[front]);
front=front+1;
}
}
void display()
{
int i;
if(front==rare)
printf("\nQ is empty");
else
{
printf("\n the element is Queues are:-\n");
for(i=front;i<rare;i++)
printf("%d\n",q[i]);
}
}
/*
1:insert
2:delete
3:display
4:exit
enter your choice:-2
the deleted element is:-6
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-2
Q is empty
do you want to continue(Y|N):-n
3:display
4:exit
enter your choice:-1
enter the element:-4
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
enter the element:-5
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-1
Q is full
do you want to continue(Y|N):-y
1:insert
2:delete
3:display
4:exit
enter your choice:-6
you entered wrong choice
do you want to continue(Y|N):-n
*/
No comments:
Post a Comment