-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path232.cpp
45 lines (36 loc) · 820 Bytes
/
232.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
class MyQueue {
public:
stack <int> temp1;
stack <int> temp2;
MyQueue() {
}
void push(int x) {
temp1.push(x);
}
int pop() {
int temp = peek();
temp2.pop();
return temp;
}
int peek() {
if(temp2.empty()){
while(!temp1.empty()){
temp2.push(temp1.top());
temp1.pop();
}
}
return temp2.top();
}
bool empty() {
if (!temp2.empty() || !temp1.empty()) return false;
return true;
}
};
/**
* Your MyQueue object will be instantiated and called as such:
* MyQueue* obj = new MyQueue();
* obj->push(x);
* int param_2 = obj->pop();
* int param_3 = obj->peek();
* bool param_4 = obj->empty();
*/