ProLesson 2 of 36 min read

Stacks and queues: last in first out vs first in first out

See how stacks and queues control the order items come out, how to build each in Python, and where each one is used.

In the last lesson you chose a container by how you look things up. Sometimes you do not look things up at all. You just need the next item, and the question is which one counts as next. Two simple structures answer that question in opposite ways: the stack and the queue.

Vidi Pro

Keep going with Pro.

The first lesson of every class is free. Pro opens every lesson in IELTS, Programming, Mathematics, Science and Data and AI, with practice questions.

Already have Pro? Log in to keep reading.

Written with AI help. Spotted a mistake? Tell us.