-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircularQueue.c
More file actions
84 lines (76 loc) · 1.29 KB
/
Copy pathcircularQueue.c
File metadata and controls
84 lines (76 loc) · 1.29 KB
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
#include <stdio.h>
#include <conio.h>
int n = 5;
int qu[5];
int f = -1, r = -1;
void insert(int x)
{
if ((f == r + 1) || (f == 0 && r == n - 1))
printf("Stack Overflow\n");
else if (f == -1 && r == -1)
{
f = 0;
qu[++r] = x;
}
else if (r == n - 1)
{
r = 0;
qu[r] = x;
}
else
qu[++r] = x;
}
void del()
{
if (f == -1 && r == -1)
printf("Stack Underflow");
else if (f == r)
{
f = -1;
r = -1;
}
else if (f == n - 1)
f = 0;
else
f++;
}
void display()
{
if (f <= r)
for (int i = f; i <= r; i++)
printf("%d ", qu[i]);
else
{
for (int i = f; i < n; i++)
printf("%d ", qu[i]);
for (int i = 0; i <= r; i++)
printf("%d ", qu[i]);
}
printf("\n");
}
int main()
{
int val;
while (1)
{
printf("1.Insert\n2.Delete\n3.Display\n4.Exit\n");
scanf("%d", &val);
switch (val)
{
case 1:
scanf("%d", &val);
insert(val);
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
break;
}
}
}