Stacks & Queues

Answer & solution
Official answer: C
1. Set up the reasoning. Choose and maintain an invariant: the queue's front is always at the stack top. Then removing the front is simply POP; a newly enqueued item must be placed at the bottom without disturbing the old order.
2. Derive the result. Keep the queue front at the stack top. ENQUEUE(x) performs REVERSE, PUSH(x), REVERSE, placing x at the bottom while preserving the previous order. DEQUEUE performs POP. Thus three and one instructions respectively, C. A single reversal followed by a pop would leave the remaining stack in the wrong orientation for an arbitrary future operation sequence.
3. Check the interpretation. REVERSE, PUSH, REVERSE inserts at the bottom and restores the invariant. Counting only the reversal and pop needed for one isolated removal ignores the orientation needed by later queue operations.

