-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10866.cpp
More file actions
60 lines (57 loc) · 1.58 KB
/
10866.cpp
File metadata and controls
60 lines (57 loc) · 1.58 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
#include <iostream>
using namespace std;
const int SIZE = 10000;
int main(){
int Deque[SIZE] = {0,};
int n, front = 0, back = 1, datasize = 0;
string str;
cin >> n;
for(int i = 0; i < n; i++){
cin >> str;
if(str == "push_front"){
int num;
cin >> num;
Deque[front] = num;
front = (front - 1 + SIZE) % SIZE;
datasize++;
}
else if(str == "push_back"){
int num;
cin >> num;
Deque[back] = num;
back = (back + 1) % SIZE;
datasize++;
}
else if(str == "pop_front"){
if(datasize == 0) cout << "-1" << endl;
else{
front = (front + 1) % SIZE;
cout << Deque[front] << endl;
datasize--;
}
}
else if(str == "pop_back"){
if(datasize == 0) cout << "-1" << endl;
else{
back = (back - 1 + SIZE) % SIZE;
cout << Deque[back] << endl;
datasize--;
}
}
else if(str == "size"){
cout << datasize << endl;
}
else if(str == "empty"){
cout << (datasize == 0) << endl;
}
else if(str == "front"){
if(datasize == 0) cout << "-1" << endl;
else cout << Deque[(front + 1) % SIZE] << endl;
}
else if(str == "back"){
if(datasize == 0) cout << "-1" << endl;
else cout << Deque[(back - 1 + SIZE) % SIZE] << endl;
}
}
return 0;
}