forked from akshitagupta15june/100code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_queue_using_arrays.c
More file actions
99 lines (95 loc) · 1.52 KB
/
Copy pathcircular_queue_using_arrays.c
File metadata and controls
99 lines (95 loc) · 1.52 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<stdio.h>
#define n 10
int queue[n];
int f=-1;
int r=-1;
void enqueue(int data)
{
if((r+1)%n==f)
{
printf("\nQUEUE OVERFLOW");
}
else if(f==-1 && r==-1)
{
f=r=0;
queue[r]=data;
}
else
{
r=(r+1)%n;
queue[r]=data;
}
}
void dequeue()
{
if(f==-1 && r==-1)
{
printf("\nQUEUE UNDERFLOW");
}
else if(f==r)
{
f=r=-1;
}
else
{
printf("\nItem deleted is %d ",queue[f]);
f=(f+1)%n;
}
}
void peak()
{
if(f==-1 && r==-1)
{
printf("\nNothing to display");
}
else
{
printf("\nPEAK VALUE IS %d ",queue[f]);
}
}
void display()
{
int i=f;
if(f==-1 && r==-1)
{
printf("\nNothing to display");
}
else
{
while(i!=r)
{
printf("\n%d \n",queue[i]);
i=(i+1)%n;
}
}
}
int main()
{
int ch,data;
do
{
printf("\nEnter following keys\n1:ENQUEUE\n2:DEQUEUE\n3:PEAK\n4:display\n5:(0) to exit\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter data\n");
scanf("%d ",&data);
enqueue(data);
break;
case 2:
dequeue();
break;
case 3:
peak();
break;
case 4:
display();
break;
default:
printf("wrong choice");
}
}
while(ch!=0);
ch=getchar();
}