blob: 13b7d6c54686425202860e985ba159c0d286394a (
plain) (
blame)
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
|
#include "header.hpp"
#include <queue>
class MyStack {
public:
MyStack() = default;
void push(int x) { q1.push(x); }
int pop() {
while (q1.size() > 1) {
q2.push(q1.front());
q1.pop();
}
auto result = q1.back();
q1.pop();
while (q2.size() > 0) {
q1.push(q2.front());
q2.pop();
}
return result;
}
int top() { return q1.back(); }
bool empty() { return q1.empty(); }
private:
std::queue<int> q1;
std::queue<int> q2;
};
/**
* Your MyStack object will be instantiated and called as such:
* MyStack* obj = new MyStack();
* obj->push(x);
* int param_2 = obj->pop();
* int param_3 = obj->top();
* bool param_4 = obj->empty();
*/
int main(int argc, char **argv) {
MyStack *obj = new MyStack();
obj->push(10);
int param_2 = obj->pop();
int param_3 = obj->top();
bool param_4 = obj->empty();
return 0;
}
|