public class MyQueue {
private Stack<Integer> stackIn, stackOut;
public MyQueue() {
// do intialization if necessary
stackIn = new Stack();
stackOut = new Stack();
}
/*
* @param element: An integer
* @return: nothing
*/
public void inToOut(Stack<Integer> stackIn, Stack<Integer> stackOut) {
while(!stackIn.isEmpty()) {
stackOut.push(stackIn.pop());
}
}
public void push(int element) {
// write your code here
stackIn.push(element);
}
/*
* @return: An integer
*/
public int pop() {
// write your code here
if(stackOut.isEmpty()) {
inToOut(stackIn, stackOut);
}
return stackOut.pop();
}
/*
* @return: An integer
*/
public int top() {
// write your code here
if(stackOut.isEmpty()) {
inToOut(stackIn, stackOut);
}
return stackOut.peek();
}
}