-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
116 lines (108 loc) · 1.79 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <stdlib.h>
int queue[10], i, size, item;
int f =-1, r = -1;
// void enq()
void enq()
{
if(r==size-1 && f == 0)
{
printf("Queue is full");
}
else
{
if(f==-1)
{
f++;
}
if(r == size-1 && f != 0)
{
r == 0;
}
else
{
r++;
}
scanf("%d",&item);
queue[r]=item;
}
}
void deq()
{
if(f==-1)
{
printf("Queue is empty");
}
else
{
item=queue[f];
if(f==r)
{
f=r=-1;
}
else
{
f++;
}
}
}
void display()
{
if(f==-1)
{
printf("Queue is empty");
}
else
{
for (i=f;i<=r;i++)
{
printf("Queue[%d] = %d\n`",i,queue[i]);
}
}
}
// void deq
// void display()
void main ()
{
int ch ;
printf("Enter the size of the queue: ");
scanf("%d",&size);
while(1)
{
printf("\nChose one from the below options...\n");
printf("\n1.Enq 2.Deq 3.Display 4.Exit");
printf("\n Enter choice \n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("Enq..\n");
enq();
break;
}
case 2:
{
printf("Dnq..\n");
deq();
break;
}
case 3:
{
printf("display...\n");
display();
break;
}
case 4:
{
printf("Exiting....\n");
exit(0);
break;
}
default:
{
printf("Please Enter valid choice ");
}
}
}
}