q1 and q2, and a variable topElement to store the top of the stack.push, enqueue the new element to q1 and update topElement.pop, transfer all elements except the last from q1 to q2, save the last element to return, and swap the references of q1 and q2.top, return topElement.empty, check if q1 is empty and return the result.