-
Notifications
You must be signed in to change notification settings - Fork 0
/
1212-Double-Ended-Queue.cpp
55 lines (49 loc) · 1.44 KB
/
1212-Double-Ended-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
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
int t, tc = 0;
cin >> t;
while(tc++ < t) {
cout << "Case " << tc << ":\n";
int n, cmd, temp;
cin >> n >> cmd;
deque<int> q;
string s;
while(cmd--) {
cin >> s;
if(s == "pushLeft") {
cin >> temp;
if(q.size() < n) {
q.push_front(temp);
cout << "Pushed in left: " << temp << endl;
}
else cout << "The queue is full" << endl;
}
else if(s == "pushRight") {
cin >> temp;
if(q.size() < n) {
q.push_back(temp);
cout << "Pushed in right: " << temp << endl;
}
else cout << "The queue is full" << endl;
}
else if(s == "popLeft") {
if(q.size() > 0) {
cout << "Popped from left: " << q.front() << endl;
q.pop_front();
}
else cout << "The queue is empty" << endl;
}
else if(s == "popRight") {
if(q.size() > 0) {
cout << "Popped from right: " << q.back() << endl;
q.pop_back();
}
else cout << "The queue is empty" << endl;
}
}
}
return 0;
}