Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.
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.
▶ 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.