-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircularqueue.c
76 lines (76 loc) · 1.38 KB
/
circularqueue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int queue[5];
int rear=0;
int front=0;
int item;
void enqueue();
void dequeue();
void display();
int main(){
int choice;
while(1)
{
printf("enter your choice 1-3:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("invalid input");
}
}
return 0;
}
void enqueue()
{
if((rear+1)%MAX==front)
{
printf("queue is full:\n");
}
else{
printf("enter item which you want to store:");
scanf("%d",&item);
queue[rear]=item;
rear ++;
}
}
void dequeue()
{
if(front==rear){
printf("queue is empty:\n");
}
else{
item=queue[front];
printf("the dequeue element is %d \n",item);
front=front+1;
}
}
void display()
{
if(rear==front)
{
printf("queue is empty\n");
}
else{
int i;
printf("queue are:\n");
for(i=front;i<=(rear-1);i++)
{
printf("%d",queue[i]);
}
}
printf("\n");
}