A-level Computer Science revision · Data structures and algorithms

Stacks, queues and linked lists

The idea

A stack is LIFO (last in, first out): push adds to the top, pop removes from the top. A queue is FIFO (first in, first out): enqueue at the rear, dequeue from the front; a circular queue reuses space. A linked list stores nodes with data and a pointer to the next node, so items can be inserted without shifting others.

  1. Stack: one pointer (top). Queue: front and rear pointers.
  2. Check for overflow (full) and underflow (empty).
  3. Linked list: insert by changing pointers.

Watch out Popping from an empty stack is an underflow error.

See it worked

Worked example

Push 3, push 7, pop, push 5. What is on top of the stack?

  1. After pushes: 3, 7 (top).
  2. Pop removes 7.
  3. Push 5: top is 5.

Answer 5

Your turn

Question 12 marks

A queue starts empty. Enqueue 4, enqueue 9, dequeue, enqueue 2. What value is at the front?

Question 21 mark

Which data structure is used to store return addresses when subroutines are called?

Choose one
Question 31 mark

What is an advantage of a linked list over an array?

Choose one

A-level Computer Science Pro, OCR H446

A-level Computer Science Pro

£119 once

Price rises to £199 on 1 January. Save £80 by joining before then.

At least 12 months of access

By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right.

No VAT is charged.

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms