Open the editor

Computer science · High school

Stacks and Queues Slides

Free animated slides, ready to teach: 6 slides where every step appears on a click and the diagrams move. Play them right here, present them full screen, or copy them into your account to edit.

A real Tracé deck playing in your browser. No account needed.

What the lesson covers

Stacks and queues are lists where you may only add and remove at certain ends. Students push and pop on a stack (last in, first out), compare it with a queue (first in, first out) and trace a sequence of operations on each.

The slides, one by one

1 Stacks and queues

Last in or first in?

Why does the undo button remove your latest change first?

2 A stack adds and removes at the top

Push puts on top; pop takes from the top

Last in, first out (LIFO)

3 A queue serves the oldest item first

Stack (LIFO)

  • Push and pop at the top
  • Undo, the call stack
  • Newest leaves first

Queue (FIFO)

  • Join at the back, leave at the front
  • Print jobs, key presses
  • Oldest leaves first

Same items, different order out

4 Tracing a stack

Start with an empty stack. Do: push 5, push 8, pop, push 2, push 7, pop, pop. What is popped, and what is left?

→ Write the stack after each step, top on the right

[5] \to [5, 8] \to \text{pop } 8 \to [5]
[5, 2] \to [5, 2, 7]
\text{pop } 7 \to [5, 2]
\text{pop } 2 \to [5]

Popped 8, 7, 2 in that order; 5 is left

5 Quick check

A queue receives A, then B, then C. One item is dequeued. Which one?

  • A
  • C
  • B
  • None
Show the answer

A

A queue is first in, first out, so A, the first to join, leaves first.

6 What to remember

Stack: last in, first out

Push and pop at the top

Queue: first in, first out

Enqueue at the back, dequeue at the front

Challenge: How could you build a queue using two stacks?

Every slide is built click by click: text, formulas and pictures come in one step at a time, so the class follows the reasoning instead of reading ahead. Graphs with sliders can be dragged live while you present.

Make your own version with AIChange the level, the numbers or the language: type the topic and get a new deck that moves in about 30 seconds. Free, no account needed.

Questions teachers ask

What is the difference between a stack and a queue?

A stack is last in, first out: you push and pop at the top, like a pile of plates. A queue is first in, first out: you join at the back and leave from the front, like people waiting at a till.

Are these slides really free?

Yes. Watch them on this page or present them full screen with no account. Making your own copy to edit is free too.

Can I change the slides before my lesson?

Yes. Press "Make my own copy" and the deck becomes one of your projects in the Tracé editor, where you can change the text, the numbers, the colours or the order of the clicks.

Do they work on a classroom projector or an interactive whiteboard?

Yes. They run in the browser on any laptop, so anything that shows your screen works. Press the right arrow or click to go to the next step.