-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwentySix.cpp
55 lines (50 loc) · 974 Bytes
/
twentySix.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 <iostream>
#include <stack>
#include <queue>
using namespace std;
queue<int> Q;
stack<int> ST;
void problem() {
int half = Q.size() / 2;
for (int i = 0; i < half; i++) {
ST.push( Q.front() );
Q.pop();
}
while (!ST.empty()) {
Q.push( ST.top() );
ST.pop();
}
for (int i = 0; i < half; i++) {
Q.push( Q.front() );
Q.pop();
}
for (int i = 0; i < half; i++) {
ST.push( Q.front() );
Q.pop();
}
while (!ST.empty()) {
Q.push( ST.top() );
ST.pop();
Q.push( Q.front() );
Q.pop();
}
}
int main(int argc, char const *argv[]) {
Q.push(11);
Q.push(12);
Q.push(13);
Q.push(14);
Q.push(15);
Q.push(16);
Q.push(17);
Q.push(18);
Q.push(19);
Q.push(20);
problem();
int l = Q.size();
for (int i = 0; i < l; i++) {
cout << Q.front() << endl;
Q.pop();
}
return 0;
}