双队列实现栈
class MyStack {
queue<int> q1,q2;
public:
MyStack() {
}
void push(int x) {
q1.push(x);
}
int pop() {
while (q1.size() > 1)
{
q2.push(q1.front());
q1.pop();
}
int ans = q1.front();
q1.pop();
while (!q2.empty())
{
q1.push(q2.front());
q2.pop();
}
return ans;
}
int top() {
return q1.back();
}
bool empty() {
if (q1.empty())
return true;
else
return false;
}
};