-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathada_and_queue.cpp
36 lines (31 loc) · 1018 Bytes
/
ada_and_queue.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define long long long int
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
deque<int> dq;
bool inv = false;
int Q; cin >> Q;
while (Q--) {
string op; cin >> op;
if (op == "reverse") inv = !inv;
else if (op == "back") {
if (dq.empty()) cout << "No job for Ada?\n";
else if (inv) cout << dq.front() << "\n", dq.pop_front();
else cout << dq.back() << "\n", dq.pop_back();
} else if (op == "front") {
if (dq.empty()) cout << "No job for Ada?\n";
else if (inv) cout << dq.back() << "\n", dq.pop_back();
else cout << dq.front() << "\n", dq.pop_front();
} else if (op == "push_back") {
int N; cin >> N;
if (inv) dq.push_front(N);
else dq.push_back(N);
} else {
int N; cin >> N;
if (inv) dq.push_back(N);
else dq.push_front(N);
}
}
}