Ch 3 · Stacks — Last In, First Out · Data Structures & Algorithms

Topic 3 of 10 in Data Structures & Algorithms — Foundations — 2 lessons.

What Is a Stack?

A stack only lets you touch the top. You push an item on top, and you pop the top item off. The last thing in is the first thing out — LIFO. Think of a pile of plates: you take the one you just put down.

Stacks in Action: Balanced Brackets

Editors check that your (, [, { all close in the right order. That is a stack: push every opener, and when you meet a closer, the top of the stack must be its match.

All topics in Data Structures & Algorithms Beginner

  1. Thinking Like a Computer Scientist
  2. Arrays & Lists — The Workhorse
  3. Stacks — Last In, First Out
  4. Queues — First In, First Out
  5. Linked Lists — Nodes on a Chain
  6. Searching — Finding the Needle
  7. Sorting — Putting Things in Order
  8. Recursion — Functions That Call Themselves
  9. Hash Tables — Instant Lookups
  10. Mini-Projects & Practice