ITPEC FE Subject B April 2025 Question 10
ITPEC FE Subject B April 2025 — Question 10 of 20
Doubly Linked List — deleteLast — remove the tail node by traversing to the end and unlinking it.
The procedure walks through the list to find the last element, then removes it by clearing the previous node's next pointer.
Blank A — loop condition:
The loop advances current forward via current ← current.next. It must stop when current reaches the last element (i.e., when current.next is undefined). So the condition is:
- while (current.next is not undefined) → A = `current.next`
Blank B — unlinking the last element:
After the loop, current points to the last node. To remove it, we need to set current.prev.next ← undefined, which disconnects the tail from the second-to-last node.
- The code reads [B] ← undefined, so B = `current.prev.next`
Why not others:
- (a) current.prev would traverse backward, not forward
- (b) current.prev same backward issue; current.next as B would set an already-undefined reference
- (c) current as loop condition would cause a null pointer error (overshoots the last node)
- (d) current.next as B is already undefined after the loop — no actual deletion
- (f) same issue as (d) for B — current.next is already undefined
Key rule: in a doubly linked list deletion, always update the neighbor's pointer (prev.next or next.prev), not the node's own pointer.
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.