/** * Removes the element on top of the stack and returns that element. */ publicintpop() { if (queueA.isEmpty() && !queueB.isEmpty()) return queueB.remove(); return queueA.remove();
}
/** * Get the top element. */ publicinttop() { if (queueA.isEmpty() && !queueB.isEmpty()) return queueB.peek(); return queueA.peek(); }
/** * Returns whether the stack is empty. */ publicbooleanempty() { if (queueA.isEmpty() && queueB.isEmpty()) returntrue; returnfalse; } }