SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 1 · 1.2j

Stacks
& Queues

LIFO · FIFO · Push · Pop · Enqueue · Dequeue

CSZoneEdexcel GCSE Computer Science 1CP2
The Stack

Last In, First Out (LIFO)

A stack is a data structure where items are added and removed from the same end (the top). The last item added is the first to be removed — LIFO (Last In, First Out). Like a stack of plates.
Push — add an item to the top of the stack
Pop — remove the item from the top of the stack
Peek — view the top item without removing it
Real-world uses: browser back button, undo function, call stack in programs
The Queue

First In, First Out (FIFO)

A queue is a data structure where items are added at the rear and removed from the frontFIFO (First In, First Out). Like a queue at a shop.
Enqueue — add an item to the rear
Dequeue — remove an item from the front
Real-world uses: print queue, keyboard buffer, CPU task scheduling
Comparing Stacks and Queues

Key Differences at a Glance

Stack (LIFO): top only — push/pop from same end. Last added = first removed.
Queue (FIFO): two ends — enqueue at rear, dequeue at front. First added = first removed.
Overflow: trying to add to a full structure. Underflow: trying to remove from an empty structure. Both are errors.
Exam Practice

Have a go at this question

Edexcel-style question
Describe how a stack data structure works and give one real-world example of where a stack is used in computing.
3 marks
A stack follows LIFO — Last In, First Out [1]. Items are added (pushed) and removed (popped) from the top only [1]. Real-world use: the undo function in software — each action is pushed onto the stack; pressing undo pops the most recent action [1].
Key Takeaways

What to Remember

Stack: LIFO — push/pop from top. Uses: undo, back button, call stack
Queue: FIFO — enqueue at rear, dequeue at front. Uses: print queue, CPU scheduling
Overflow = adding to full structure; Underflow = removing from empty structure
Stacks and queues are abstract data types — they define behaviour, not implementation