ITPEC IP April 2021 Question 7
ITPEC IP April 2021 — Question 7 of 100
Z, X, Y cannot be produced with one stack. To output Z first, the earlier arrivals X and Y must both be pushed while Z is passed through or later popped. The stack then holds X below Y. Because a stack is LIFO, Y must leave before X, so the remaining order can only be Y, X, not X, Y.
Answer (c)
Why not others:
- X, Z, Y: pass X, push Y, pass Z, then pop Y
- Y, Z, X: push X, pass Y and Z, then pop X
- Z, Y, X: push X and Y, pass Z, then pop Y and X
Key rule: Once two items are pushed in arrival order, they can leave only in reverse order.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.