-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathI_Ada_and_Queue.cpp
94 lines (89 loc) · 2.11 KB
/
I_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
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
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
deque<int> DequeInst;
bool reversed = false;
int operationsCount = 0;
cin >> operationsCount;
while (operationsCount--)
{
string operation;
cin >> operation;
if (operation == "toFront")
{
int x;
cin >> x;
if (!reversed)
{
DequeInst.push_front(x);
}
else
{
DequeInst.push_back(x);
}
}
else if (operation == "front")
{
if (!DequeInst.empty())
{
if (!reversed)
{
cout << DequeInst.front() << endl;
DequeInst.pop_front();
}
else
{
cout << DequeInst.back() << endl;
DequeInst.pop_back();
}
}
else
{
cout << "No job for Ada?" << endl;
}
}
else if (operation == "back")
{
{
if (!DequeInst.empty())
{
if (!reversed)
{
cout << DequeInst.back() << endl;
DequeInst.pop_back();
}
else
{
cout << DequeInst.front() << endl;
DequeInst.pop_front();
}
}
else
{
cout << "No job for Ada?" << endl;
}
}
}
else if (operation == "push_back")
{
int x;
cin >> x;
if (!reversed)
{
DequeInst.push_back(x);
}
else
{
DequeInst.push_front(x);
}
}
else if (operation == "reverse")
{
reversed = !reversed;
}
}
}