ITPEC FE Subject B October 2025 Question 10

Source exam: ITPEC FE Subject B October 2025Topic: Linked List

ITPEC FE Subject B October 2025 — Question 10 of 20

The procedure insertAfter(targetData, newData) traverses a singly linked list starting from head, finds the node whose data matches targetData, and inserts a new node with newData immediately after it.

  • Blank A — loop condition: The traversal must continue while x is a valid node. The end of the list is signaled by x being undefined, so the condition is not undefined.

- Blank B — linking the new node: When inserting node y after node x, the standard two-step pointer update is:
1. y.next ← x.next — the new node takes over the link to whatever followed x

2. x.next ← yx now points to the new node

If y.next were set to anything else (e.g., head, x, or x.next.next), the list would lose nodes or create incorrect links.

Why not others:
- a) B = head would point the new node back to the start, breaking the list

- b) B = x would create a circular reference between x and y

- c) B = x.data is a string, not a node reference — type mismatch

- e) B = x.next.next would skip a node, losing it from the list

- f–j) A = undefined would mean the loop runs while x IS undefined, which is the opposite of what we need — the loop body would never execute

Key rule: When inserting into a linked list, always save the "next" pointer of the current node before overwriting it — otherwise you lose the rest of the list.

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 FE past-paper collection or Report an issue.