-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-QueueUsingArray.c
More file actions
83 lines (78 loc) · 1.66 KB
/
Copy path2-QueueUsingArray.c
File metadata and controls
83 lines (78 loc) · 1.66 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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct {
/*
The queue should contain an array to hold a maximum of 10 elements.
*/
int arr[50];
} Queue;
/*
Initialising the queue, use this queue variable 'q' in your functions.
*/
Queue q;
int front = 0, end = 0;
void enqueue(int n) {
/*
Enqueue the integer n into the queue.
Ignore if the operation is not possible.
*/
if(end - front < 9){
q.arr[end++] = n;
}
}
int dequeue() {
/*
Dequeue the front element from the queue and return that element.
Return -1 the operation is not possible.
*/
int temp;
if(end == front){
return -1;
}
else{
temp = q.arr[front++];
return temp;
}
}
bool isEmpty() {
/*
Check if the queue is empty or not. Return true/false.
*/
if(end == front)
return true;
else
return false;
}
bool isFull() {
/*
Check if the queue is full or not. Return true/false.
*/
if(end - front == 9)
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;
// case 4: ;
// Stack temp;
// pop(&temp);
// push(&temp, n);
// break;
}
}
return 0;
}