9618/22/M/J/23 question 3: worked solution (May/June 2023, paper 22)

Show as plain text

Cambridge AS Level Computer Science 9618 · 10.4 Introduction to Abstract Data Types (ADT) Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4. Q74 9618/22/M/J/23 original Q3 Structured · 10 marks Worked solution (a)(i) The queue holds Red to Pink in locations 5 to 8, so there is space. Check that the queue is not full [1] The End of Queue pointer moves to location 9 [1] Orange is stored in the location the End of Queue pointer points to (9) [1] The End of Queue pointer then moves on to location 0 (it wraps round because the queue is circular) [1] Also credited: Yellow is stored in location 0 (maximum 4 marks in total). (a)(ii) Front is at location 5 and End is at location 1. Items are in 5, 6, 7, 8, 9, 0, 1. Write: 7 [1] (b) Write the steps in words: Open the file in READ mode [1] Loop until the end of the file (EOF) so every line is processed [1] The loop also ends when AddToQueue() returns FALSE, meaning the queue is full [1] Read a line from the file inside the loop [1] Pass the line (string) to AddToQueue() as the parameter [1] KEY IDEA A circular queue moves its end pointer on and wraps to 0; a file loop ends at end of file or when the queue is full. TOTAL 10 marks Official mark scheme VIDEO ▶ Starts at Q3 (15:19) Starts at Q3 (15:19) · by Pseudocode Pro. Tap the picture to open it on YouTube.