💻 Computer Science · Topic 97 of 97

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.

Loading animation…

📘 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

Common mistakes to avoid

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.

← PreviousCookies and Online TrackingNext →What Is a Computer?

Keep exploring Computer Science