-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathAC_simulation_n.cpp
58 lines (48 loc) · 1.05 KB
/
AC_simulation_n.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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2015-07-20 21:13:54
* Descripton:
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Stack {
private:
queue<int> q;
public:
// Push element x onto stack.
void push(int x) {
q.push(x);
}
// Removes the element on top of the stack.
void pop() {
queue<int> q2(q);
while (!q.empty())
q.pop();
while (q2.empty()) {
int tmp = q2.front();
q2.pop();
if (q2.empty()) // ignore last element in q2
break;
q.push(tmp);
}
}
// Get the top element.
int top() {
queue<int> q2(q);
while (q2.empty()) {
int tmp = q2.front();
q2.pop();
if (q2.empty()) // ignore last element in q2
return tmp;
}
}
// Return whether the stack is empty.
bool empty() {
return q.empty();
}
};
int main() {
return 0;
}