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