Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.
Declare a constant for the size, two integer pointers (bottom and top) and a string array of 100 items.
CONSTANT Maximum = 100 DECLARE Base : INTEGER DECLARE Top : INTEGER DECLARE StackArray : ARRAY[1:100] OF STRING
Constant Maximum = 100 declared correctly [1]
Both pointers Base and Top declared as INTEGER [1]
Array StackArray declared with 100 elements of type STRING [1]
Write a procedure that sets both pointers to starting values for an empty stack.
PROCEDURE InitialiseStack()
Base ← 0
Top ← 0
ENDPROCEDURECorrect procedure structure (PROCEDURE ... ENDPROCEDURE) [1]
Base set to a suitable value (0 or 1) [1]
Top set to a suitable value (-1, 0 or 1) [1]
The values must fit the array bounds you declared in part (a).
▶ Topic lesson
A lesson on this topic · by rjmcompsci. 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.