Cambridge AS Level Computer Science 9618 · 10.4 Introduction to Abstract Data Types (ADT)

Q82 · 9618/21/M/J/25 Q5

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.

Q829618/21/M/J/25original Q5Structured · 7 marks
Question 5 from 9618/21/M/J/25

Worked solution

Move the items from the stack to the queue, then from the queue back to the stack. Any seven of these points score.

Pop an item off the stack [1]

Add that item to the queue [1]

Repeat until the stack is empty [1]

Remove an item from the queue [1]

Push it onto the stack [1]

Repeat until the queue is empty [1]

Update the pointers (top of stack, rear and front) each time an item is moved [1]

Other points that also score: update the top-of-stack pointer (down) after the pop; update the rear pointer after the add; update the front pointer after the remove; update the top-of-stack pointer (up) after the push. Each of these can score in place of the pointer mark above.

Item 6 goes into the queue first and comes out first, so it is pushed first and ends at the bottom of the stack.

KEY IDEAA stack reverses order when popped, and a queue keeps order, so moving items stack → queue → stack reverses the stack.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/21/M/J/25 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by Sir Sikandar Raza. 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.