forked from sanjaysunil34/hacktober2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-QueueUsingArray.c
More file actions
69 lines (61 loc) · 1.24 KB
/
2-QueueUsingArray.c
File metadata and controls
69 lines (61 loc) · 1.24 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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct {
int arr[10];
}Queue;
Queue q;
int front=-1,rear=-1;
void enqueue(int n) {
if(rear==-1){
front=rear=0;
q.arr[rear]=n;
}
else if(rear<9)
q.arr[++rear]=n;
}
int dequeue() {
if(front==-1)
return -1;
else if(front == rear){
int temp = front;
front = -1;
rear = -1;
return q.arr[temp];
}
else
return q.arr[front++];
}
bool isEmpty() {
if(front == -1)
return 1;
return 0;
}
bool isFull() {
if(rear==9 && front==0)
return 1;
return 0;
}
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;
// case 4: ;
// Stack temp;
// pop(&temp);
// push(&temp, n);
// break;
}
}
return 0;
}