-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode 232.cpp
More file actions
35 lines (33 loc) · 795 Bytes
/
Copy pathLeetcode 232.cpp
File metadata and controls
35 lines (33 loc) · 795 Bytes
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
class MyQueue {
public:
stack<int>s1;
stack<int>s2;
MyQueue() {
}
//Pushes element x to the back of the queue.
void push(int x) {
while(s1.empty()==false){
s2.push(s1.top());
s1.pop();
}
s2.push(x);
while(s2.empty()==false){
s1.push(s2.top());
s2.pop();
}
}
//Removes the element from the front of the queue and returns it.
int pop() {
int front=s1.top();
s1.pop();
return front;
}
// Returns the element at the front of the queue.
int peek() {
return s1.top();
}
//Returns true if the queue is empty, false otherwise.
bool empty() {
return s1.empty();
}
};