Stacks and Queues
Aligned to the AQA 7517 specification
- Level
- Intermediate
- Reading time
- 9 min
- Published
- 6 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- A stack is a Last In, First Out (LIFO) structure: push, pop and peek all act on the top, and the top pointer holds the index of the current top element (top = −1 when empty).
- A queue is a First In, First Out (FIFO) structure: items are enqueued at the rear and dequeued from the front, using separate front and rear pointers.
- An abstract data type is defined by its operations and behaviour, not its implementation, so the underlying storage (e.g. array or linked list) can change without affecting code that uses it.
- A circular queue wraps the rear pointer using rear = (rear + 1) mod maxSize to reuse slots freed at the front, fixing the linear queue's wasted space.
- In a priority queue dequeue removes the highest-priority item regardless of arrival order; FIFO ordering applies only between items of equal priority.
Something not quite clicking?
Ask Aica to explain any part of this differently. Free, takes 30 seconds.
Key terms
- Abstract data type (ADT)
- A data structure defined by its operations and behaviour rather than by how it is implemented internally.
- Stack
- A linear LIFO structure where elements are added and removed from the same end, the top.
- Queue
- A linear FIFO structure where elements are added at the rear and removed from the front.
- LIFO
- Last In, First Out: the most recently added element is the first to be removed, as in a stack.
- FIFO
- First In, First Out: the first element added is the first to be removed, as in a queue.
- Top pointer
- The index of the current top element of a stack; an empty stack has top = −1.
- Stack overflow
- The error caused by pushing an item onto a full stack.
- Stack underflow
- The error caused by popping from an empty stack.
- Circular queue
- A queue that wraps the rear pointer back to index 0 when it reaches the end of the array, using modulo arithmetic to reuse freed slots.
- Priority queue
- A queue variant where each item has a priority value and dequeue removes the highest-priority item first, with FIFO order within equal priorities.
- peek
- An operation that returns the front or top item without removing it, leaving the pointer unchanged.
Frequently asked questions
A stack is Last In, First Out (LIFO): items are added and removed at the same end, the top, so the most recently added item is removed first. A queue is First In, First Out (FIFO): items are added at the rear and removed from the front, so the first item added is removed first.
In a linear queue the front pointer only moves right, so once the rear reaches the end of the array the queue reports full even when space exists at the front. A circular queue wraps the rear back to index 0 using (rear + 1) mod maxSize, reclaiming those slots.
Dequeue removes and returns the item with the highest priority, not the one that arrived first. If two items share the same priority they are served in FIFO order, so a later-arriving higher-priority item is served before an earlier lower-priority one.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Arrays and Abstract Data Types
Graphs
Related lessons
5 min
6 min
6 min