Six original Cambridge-style questions on stacks, queues and linked lists, with pointer traces and mark points.
Explain what is meant by an abstract data type (ADT) and name two examples.
A stack uses Stack : ARRAY[1:5] OF INTEGER, so an empty stack has TopOfStack = 0. Starting from empty, these operations are carried out: PUSH 12, PUSH 30, PUSH 7, POP, POP, PUSH 25, PUSH 18, PUSH 4, PUSH 9. State (a) the values returned by the POP operations, (b) the final value of TopOfStack and the contents of the stack, (c) what would happen with a further PUSH 6.
A circular queue uses Queue : ARRAY[0:4] with FrontPointer = 0, RearPointer = −1 and NumberInQueue = 0. These operations are carried out: ENQUEUE 10, ENQUEUE 20, ENQUEUE 30, DEQUEUE, DEQUEUE, ENQUEUE 40, ENQUEUE 50, ENQUEUE 60. State the final values of the three variables and the next item to be dequeued.
Describe how a queue can be implemented using an array.
A linked list of integers in ascending order is stored using arrays, with −1 as the null pointer.
| Index | Data | Pointer |
|---|---|---|
| 0 | 27 | 2 |
| 1 | 9 | 0 |
| 2 | 41 | −1 |
| 3 | 4 | |
| 4 | −1 |
StartPointer = 1 and FreeListPointer = 3. (a) 30 is inserted. Give the new contents of the Pointer array and the values of StartPointer and FreeListPointer. (b) 5 is then inserted. Give the values that change.
For each situation, state whether a stack, a queue or a linked list is most suitable and justify your choice: (a) the undo feature of a graphics program, (b) callers waiting to speak to a helpline, (c) a list of contacts kept in alphabetical order where contacts are often added and removed.
Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.