Stack
A stack is a data structure that is organized like a stack of plates organized one top of each other. You only have access to the plate on top, you can peek
at it, pop
it off the stack or push
a new plate on the stack. The stack you put on the stack last is the plate you take out first. A stack has three basic operations:
peek
: Get the first item on top of the stack without removing it. $O(1)$pop
: Get the first item on top of the stack and remove it. $O(1)$push
: Put a new item on top of the stack. $O(1)$