class MyStack {
public:
/** Initialize your data structure here. */
MyStack() {
input = new queue<int>();
output = new queue<int>();
}
/** Push element x onto stack. */
void push(int x) {
input->push(x);
while(!output->empty()){
input->push(output->front());
output->pop();
}
queue<int> *p = input;
input = output;
output = p;
}
/** Removes the element on top of the stack and returns that element. */
int pop() {
if(output->empty()) return 0;
int r = output->front();
output->pop();
return r;
}
/** Get the top element. */
int top() {
return output->front();
}
/** Returns whether the stack is empty. */
bool empty() {
return output->empty();
}
private :
queue<int>* input,*output;
};