ITPEC FE Subject B October 2025 Question 7
ITPEC FE Subject B October 2025 — Question 7 of 20
The function reverseList(head, elm) reverses a singly linked list recursively. head is the current node being processed, and elm is the previously processed node (starts as undefined).
- •Recursive step: If
head.nextis not undefined, recurse withreverseList(head.next, head)— move forward in the list, passing the current node as the new "previous" - •Base case: When
head.nextis undefined, we've reached the last node — it becomes the newlistHead - •Re-linking: After recursion, set
head.next ← elmto reverse the pointer direction
| Blank | Value | Why |
|---|---|---|
| A | head.next | We recurse on the next node, passing current head as the accumulated reversed tail |
| B | elm | Each node's next pointer is redirected to the previous node (elm) |
Why not others:
- b) elm.next for B would point head to a node further back, breaking the chain
- c) elm.next for A would skip the natural traversal order; head.next.next for B makes no sense
- d) elm.next for A is wrong — we traverse via head.next, not elm.next
- e) Same problem as d) for A; elm.next for B creates incorrect linkage
Key rule: In recursive linked list reversal, each call processes the next node (head.next) and re-links the current node to point back to the previous node (elm).
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.