Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.
Match each description to its name in the code:
| Identifier | Data type | Description |
|---|---|---|
| Queue | STRING | An array to store the contents of the queue. |
| RearPointer | INTEGER | Points to the last item of the queue. |
| Length | INTEGER | Indicates the number of items in the queue. |
| FrontPointer | INTEGER | Points to the first item of the queue. |
Queue and RearPointer correct [1]
Length and FrontPointer correct [1]
Both pointers start at -1 and the length at 0. Only add an item if the queue is not full, move the rear pointer (wrapping round to 0), store the item, then increase Length.
PROCEDURE Initialise
FrontPointer ← -1
RearPointer ← -1
Length ← 0
ENDPROCEDURE
PROCEDURE Enqueue(NewItem : STRING)
IF Length < MaxLength THEN
RearPointer ← RearPointer + 1
IF RearPointer > MaxLength - 1 THEN
RearPointer ← 0
ENDIF
Queue[RearPointer] ← NewItem
Length ← Length + 1
ENDIF
ENDPROCEDURERearPointer ← -1 [1]
Length ← 0 [1]
IF Length < MaxLength THEN [1]
RearPointer ← RearPointer + 1 [1]
Queue[RearPointer] ← NewItem [1]
Write any three of these:
Print jobs should be done in the order they arrive [1]
A queue is first in, first out, so the first job sent is the first printed [1]
With a stack (last in, first out), the first job would wait until every other job had been printed [1]
▶ Whole paper
Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.