-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2QueueUsingArray.c
More file actions
70 lines (64 loc) · 1.1 KB
/
Copy path2QueueUsingArray.c
File metadata and controls
70 lines (64 loc) · 1.1 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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct {
int a[10];
} Queue;
Queue q;
int front=0;
int rear=0;
void enqueue(int n) {
if(rear<9)
{
q.a[rear]=n;
rear++;
}
}
int dequeue() {
if(rear == front)
{
return -1;
}
else
{
front++;
return q.a[front-1];
}
}
bool isEmpty() {
if(front==rear)
{
return true;
}
else
{
return false;
}
}
bool isFull() {
if(rear==9 && front==0)
{
return true;
}
else {
return false;
}
}
int main() {
int q, choice, n;
scanf("%d", &q);
while(q--) {
scanf("%d%d", &choice, &n);
switch(choice) {
case 0: enqueue(n);
break;
case 1: printf("%d\n", dequeue());
break;
case 2: printf("%d\n", isEmpty());
break;
case 3: printf("%d\n", isFull());
break;
}
}
return 0;
}