-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_impl.cpp
More file actions
58 lines (49 loc) · 816 Bytes
/
queue_impl.cpp
File metadata and controls
58 lines (49 loc) · 816 Bytes
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
#include <cstdio>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <list>
#include <set>
#include <map>
using namespace std;
// queue implementation using array.
// can be used for BFS graph traversal.
const int N = 100010;
int que[N], b, e; // begin, end.
inline void pop() {
if (b < e) {
b++;
}
}
inline int front() {
if (b < e) {
return que[b];
}
return -1;
}
inline void push(int val) {
que[e++] = val;
}
inline bool isEmpty() {
return (b >= e);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
push(x);
}
while (!isEmpty()) {
printf("%d ", front());
pop();
}
putchar('\n');
}