Skip to main content

Stack

SpaceTime
AccessLookupInsertionDeletion
O(n)O(n)O(n)O(1)O(1)

Definition​

Stack is a data structure that stores items in a Last-In-First-Out (LIFO) manner, meaning the most recently added item is the first one to be removed.

Simplified

You have a stack of plates. You can only put a new plate on the top of the stack, and you can only take the plate that's on the top. You can't take the ones in the middle until you've take the ones on top of them.

Practice​

AspectPseudo Code
Peekpeek(): stack.show_last()
Pushpush(): stack.add_to_end(data)
Poppop(): stack.pop_from_end()