Data Structures · Computer science

Stack

Stack is an interactive experiment in Data Structures, a free simulation from StudyFi Lab that runs right in your browser.

A stack works like a pile of plates: you add (push) and remove (pop) only at the top, so the last item in is the first one out (LIFO). The top pointer marks the top; push and pop both take O(1). Undo in an editor, the browser’s back button and function calls in a program (the call stack) all use one.

Try this: Push 1, 2, 3, then pop three times — the numbers come out in reverse order. Then try a ninth push.

Frequently asked questions

What does the “Stack” experiment show?

A stack works like a pile of plates: you add (push) and remove (pop) only at the top, so the last item in is the first one out (LIFO). The top pointer marks the top; push and pop both take O(1). Undo in an editor, the browser’s back button and function calls in a program (the call stack) all use one.

How do I try “Stack”?

Push 1, 2, 3, then pop three times — the numbers come out in reverse order. Then try a ninth push.

Studying for a test?

Upload your notes and StudyFi turns them into flashcards, tests and podcasts.

Try StudyFi free