-
Notifications
You must be signed in to change notification settings - Fork 1
/
Queue.c
82 lines (76 loc) · 1.04 KB
/
Queue.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
77
78
79
#include<stdio.h>
int Q[20],f=-1,r=-1,i;
void insert(int b);
void delete();
void display();
void main()
{
int n,a;
printf("\nEnter the limit of Queue : ");
scanf("%d",&a);
l:
printf("\n1.Enqueue\n2.Dequeue\n3.Display\n4.Exit");
printf("\nEnter the choice : ");
scanf("%d",&n);
switch(n)
{
case 1:insert(a);
goto l;
case 2:delete();
goto l;
case 3:display();
goto l;
case 4:break;
default:printf("\nWrong Selection");
goto l;
}
}
void insert(int b)
{
if(r==b-1)
{
printf("\nQueue is Overflow ");
}
else if(f==-1&&r==1)
{
f=0;
r=0;
printf("\nEnter the Element : ");
scanf("%d",&Q[r]);
}
else
{
r++;
printf("\nEnter the Element : ");
scanf("%d",&Q[r]);
}
}
void delete()
{
if(f==-1&&r==-1)
{
printf("\nQueue is Underflow ");
}
else if(f==r)
{
printf("\n%d is deleted",Q[f]);
f=r=-1;
}
else
{
printf("\n%d is deleted",Q[++f]);
}
}
void display()
{
if(f==r)
{
printf("\nQueue is empty ");
}
else
{
printf("\nQueue : ");
for(i=f+1;i<=r;i++)
printf("%d\t",Q[i]);
}
}