Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.
Put the five items in order in consecutive places, with the front at D3 and the end at D5. One correct layout starts at index 2.
| Index | Array |
|---|---|
| 1 | |
| 2 | D3 |
| 3 | D4 |
| 4 | D1 |
| 5 | D2 |
| 6 | D5 |
| 7 | |
| 8 |
D3, D4, D1, D2 and D5 in order (or reversed) in five consecutive places [1]
| Variable | Value |
|---|---|
| FrontOfQueue | 2 |
| EndOfQueue | 6 |
| NumItems | 5 |
FrontOfQueue holds the index of D3 [1]
EndOfQueue holds the index of D5 [1]
Complete each step. The array has 8 elements, so the pointer wraps from 8 back to 1.
1. If NumItems is 8 (the queue is full) then jump to step 6. [1]
2. Increment EndOfQueue. [1]
3. If EndOfQueue = 9 then set EndOfQueue to 1. [1]
4. Increment NumItems. [1]
5. Set the element at the index stored in EndOfQueue to the value being added. [2]
▶ Starts at Q3 (44:06)
Starts at Q3 (44:06) · by Zafar Ali Khan (ZAK). 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.