Data Structures: Stacks and Queues
A stack is a last-in first-out list and a queue is a first-in first-out list, two simple ways to organise data.
▶ Interact
Play with the controls to see the idea in action.
📘 Learn
A stack is a last-in first-out list and a queue is a first-in first-out list, two simple ways to organise data.
- Stack: push and pop
- Queue: enqueue and dequeue
- Undo uses a stack and printing uses a queue
🧠 Quick quiz
Three questions. Score 2 or more to complete the topic.
What is Data Structures: Stacks and Queues?
Within Computer Science, which covers algorithms, programming, data, networks, hardware and safe, responsible use of technology, this topic explains Data Structures: Stacks and Queues. Computing topics explain how software, hardware and data work, with diagrams and models that show each step in order.
Check that you can explain Data Structures: Stacks and Queues in your own words and give one example from everyday life. If you can do that, you have understood the core idea.
Understanding Data Structures: Stacks and Queues helps you design, test and explain programs, websites and systems, from small projects to exam questions.
Data Structures: Stacks and Queues in detail
A stack is a data structure that follows last in, first out (LIFO): the last item added is the first removed, like a stack of plates. The main operations are push (add to the top), pop (remove the top) and peek (look at the top). Stacks are used for undo features, browser back buttons and keeping track of function calls.
A queue follows first in, first out (FIFO): items are added at the back (enqueue) and removed from the front (dequeue), like people waiting in line. Queues are used for print jobs, handling requests and task scheduling. Both can be built with arrays or linked lists, and they show how the choice of structure affects how data is handled.
How the interactive helps you understand Data Structures: Stacks and Queues
Click a card to flip it and reveal the answer, then move on to the next one.
Before you change anything, predict the result. Then change one value at a time and check whether your prediction was right. This is a quick way to build a correct mental model of Data Structures: Stacks and Queues.
Real-life uses and examples
- Apply Data Structures: Stacks and Queues when you design a small program, website or spreadsheet.
- Explain Data Structures: Stacks and Queues to someone new to computing by comparing it to a familiar process.
- Trace through a process that uses Data Structures: Stacks and Queues to check what it does step by step.
Common mistakes to avoid
- Testing only the normal case and forgetting the edge cases.
- Using the term without being able to say what the computer actually does.
- Learning the definition without testing it. Use the quiz and the interactive to check that you can apply the idea.
Frequently asked questions about Data Structures: Stacks and Queues
What is Data Structures: Stacks and Queues?
A stack is a last-in first-out list and a queue is a first-in first-out list, two simple ways to organise data.
What are the most important points about Data Structures: Stacks and Queues?
The main points are: Stack: push and pop; Queue: enqueue and dequeue; Undo uses a stack and printing uses a queue.
Why is Data Structures: Stacks and Queues useful?
Understanding Data Structures: Stacks and Queues helps you design, test and explain programs, websites and systems, from small projects to exam questions.
How can I practise Data Structures: Stacks and Queues?
Open the interactive at the top of this page and change the controls one at a time. Predict the result before each change, then take the three-question quiz. A score of two or more marks the topic as complete on this device.
Which topics are related to Data Structures: Stacks and Queues?
Related topics in Computer Science include The CPU, Secondary Storage, Binary Numbers.