#include<stdio.h>
#include<conio.h>
#define
qsize 5
typedef
struct
{
int rear,front;
int a[qsize];
}queue;
queue q;
void main()
{
void add(int
x);
void
(int *x);
void show();
int choice,value;
q.front=q.rear=0;
do
{
clrscr();
printf("\n\t\t\tQUEUE");
printf("\n\t\t\t*****");
printf("\nMENU");
printf("\n====");
printf("\n\t1.INSERT");
printf("\n\t2.DELETE");
printf("\n\t3.SHOW");
printf("\n\t4.EXIT");
printf("\n\n ENTER THE CHOICE:->");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nENTER
THE VALUE:->");
scanf("%d",&value);
add(value);
getch();
break;
case 2:
(&value);
getch();
break;
case 3:
show();
getch();
break;
case 4:
exit(0);
getch();
break;
}
}while(choice!=4);
}
void add(int x)
{
int t=q.rear;
q.rear=(q.rear+1) % qsize;
if(q.front==q.rear)
{
printf("\n QUEUE IS FULL");
q.rear=t;
return;
}
else
{
q.a[q.rear]=x;
printf("\n%d IS ADDED",x);
}
}
void
(int *x)
{
if(q.front==q.rear)
printf("\n QUEUE IS EMPTY");
else
{
q.front=(q.front+1)%qsize;
*x=q.a[q.front];
printf("\n%d IS DELETED",*x);
}
}
void show()
{
int i;
if(q.front==q.rear)
printf("\nQUEUE IS EMPTY");
else
{
i=q.front;
do
{
i=(i+1)%qsize;
printf("\n %d",q.a[i]);
}
while(i!=q.rear);
}
}
No comments:
Post a Comment