一、题目
二、思路
三、代码
class MyStack {
public:
queue<int>s,t;
MyStack() {
}
void push(int x) {
t.push(x);
while(!s.empty()){
t.push(s.front());
s.pop();
}
swap(s,t);
}
int pop() {
int x=s.front();
s.pop();
return x;
}
int top() {
return s.front();
}
bool empty() {
if(s.empty()){
return true;
}
return false;
}
};
/**
* 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();
*/