ITPEC IP October 2022 Question 7

Source exam: ITPEC IP October 2022Topic: Algorithm and Programming

ITPEC IP October 2022 — Question 7 of 100

The device cannot output Z, X, Y. To output Z first, both X and Y must already have been pushed before Z arrives; Z is then pushed and popped first. The stack beneath it has Y above X, so Y must be popped before X. Therefore outputting X immediately after Z is impossible.

Answer (c)

Why not others:
- X, Z, Y is possible by sending X directly and reversing Y and Z on the stack

- Y, Z, X is possible by stacking X, sending Y directly, then handling Z and X

- Z, Y, X is obtained by pushing all three and popping them

Key rule: A stack reverses the order of stored items; once X is below Y, X cannot leave before Y.

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.