-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathAC_simulation_n.cpp
63 lines (54 loc) · 1.18 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
58
59
60
61
62
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2015-07-26 16:52:32
* Descripton:
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Queue {
private:
stack<int> stk;
public:
// Push element x to the back of queue.
void push(int x) {
stk.push(x);
}
// Removes the element from in front of queue.
void pop(void) {
// reverse the stack first
stack<int> stk2;
while (!stk.empty()) {
stk2.push(stk.top());
stk.pop();
}
stk2.pop();
while (!stk2.empty()) {
stk.push(stk2.top());
stk2.pop();
}
}
// Get the front element.
int peek(void) {
// reverse the stack first
stack<int> stk2;
while (!stk.empty()) {
stk2.push(stk.top());
stk.pop();
}
int top = stk2.top();
while (!stk2.empty()) {
stk.push(stk2.top());
stk2.pop();
}
return top;
}
// Return whether the queue is empty.
bool empty(void) {
return stk.empty();
}
};
int main() {
return 0;
}