-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path40.h
48 lines (42 loc) · 822 Bytes
/
40.h
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
class MyQueue {
public:
MyQueue() {
// do intialization if necessary
}
/*
* @param element: An integer
* @return: nothing
*/
void push(int element) {
// write your code here
s1.push(element);
}
/*
* @return: An integer
*/
int pop() {
// write your code here
int p = top();
s2.pop();
return p;
}
/*
* @return: An integer
*/
int top() {
// write your code here
reverse();
return s2.top();
}
private:
stack<int> s1;
stack<int> s2;
void reverse(){
if(!s2.empty()) return;
while(!s1.empty()){
//cout << "reverse " << s1.top() << endl;
s2.push(s1.top());
s1.pop();
}
}
};