A stack is an .
It has interesting behaviour → LAST IN FIRST OUT LIFO
We can push(item) onto the top of the stack.
We can pop() items from the stack (ie remove them) and then update the top of the stack.
We can peek() at the item at the top of the stack without popping it!
We can check if a stack isFull()
We can check if a stack isEmpty()
Check out this simulation in which a stack is implemented on a static 1-dimensional array of length 5.
Stack
| 4 | ||
| 3 | ||
| 2 | ||
| 1 | ||
| 0 |
top
-1
Here is another stack simulation. With this one, the top of the stack is always the next available element, not the latest element.
stack array push pop lifo full empty