forked from Subhajitroy03/DSA-3rdSem-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircularQueue
87 lines (87 loc) · 1.14 KB
/
CircularQueue
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
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#define max 5
int q[max];
int f=-1;
int r=-1;
void enqueue(int v)
{
if ((r+1)%max==f)
{
printf("Circular Queue Full\n");
}
else
{
if (f==-1)
f=0;
r=(r+1)%max;
q[r]=v;
}
}
void dequeue()
{
if (f==-1)
printf("Circular Queue Empty\n");
else
{
printf("Deleted Element = %d\n",q[f]);
if (f==r)
{
printf("Queue Reset\n");
f=-1;
r=-1;
}
else
{
f=(f+1)%max;
}
}
}
void display()
{
int i;
if (f==-1)
printf("Circular Queue Empty\n");
else
{
i=f;
printf("Queue :\n");
while (i!=r)
{
printf("%d ",q[i]);
i=(i+1)%max;
}
printf("%d\n",q[r]);
}
}
int main(void)
{int c,n;
while (1)
{
printf("1. Entry the Queue\n");
printf("2. Delete from the Queue\n");
printf("3. Display\n");
printf("Enter your choice(anyother to terminate)\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("Enter the element\n");
scanf("%d",&n);
enqueue(n);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
default:
printf("Final ");
display();
printf("-------PROGRAM TERMINATED--------\n");
exit(0);
}
}
return 0;
}