Stack¶
Definition¶
A Stack is a data structure where elements are inserted into and removed from the head of the container.
![An example of a data stack. Source: https://en.wikibooks.org/wiki/Data_Structures/Stacks_and_Queues](https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Data_stack.svg/391px-Data_stack.svg.png)
Motivation¶
Sequential
Limited access
Last-In First-Out (LIFO) access
Linear
- When might I actually use this?
- Towers of Hanoi puzzle
- Rearranging railroad cars
- Sorting...anything
Attributes¶
- top
- is_empty
- size
Operations¶
- push(item)
- pop()