SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 2 · 2.4b

Lists, Stacks
& Queues

LIFO · FIFO · Push/Pop · Enqueue/Dequeue · Real-world Uses

CSZoneEdexcel GCSE Computer Science 1CP2
The Stack — LIFO

Last In, First Out

A stack is a LIFO data structure — the last item added is the first to be removed. Like a stack of plates. The top is the only accessible point.
Push: add an item to the top of the stack
Pop: remove the top item from the stack
Peek: view the top item without removing it
Real-world use: undo function in software, call stack in programming, back button in browsers
The Queue — FIFO

First In, First Out

A queue is a FIFO data structure — the first item added is the first to be removed. Like a queue of people at a checkout.
Enqueue: add item to the back of the queue
Dequeue: remove item from the front of the queue
Real-world use: print queue, job scheduling, buffering in streaming
Circular queue: when the end wraps around to the beginning — efficient use of memory
Stack vs Queue in Python

Using Lists to Implement Both

# Stack using list
stack = []
stack.append(10) # push
stack.append(20)
top = stack.pop() # pop → 20

# Queue using list
queue = []
queue.append("A") # enqueue
front = queue.pop(0) # dequeue → "A"
Exam Practice

Have a go at this question

Edexcel-style question
A program uses a stack. The following operations are performed in order: Push 3, Push 7, Push 1, Pop, Push 5, Pop. State the contents of the stack after all operations.
3 marks
Push 3 → [3]
Push 7 → [3,7]
Push 1 → [3,7,1]
Pop → removes 1 → [3,7]
Push 5 → [3,7,5]
Pop → removes 5 → [3, 7] [3 marks]
Key Takeaways

What to Remember

Stack: LIFO — Push adds, Pop removes from the TOP
Queue: FIFO — Enqueue adds to back, Dequeue removes from front
Stack use: undo, call stack; Queue use: print queue, scheduling
Python: stack → list.append/pop(); queue → list.append/pop(0)