mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
41 lines
603 B
Markdown
41 lines
603 B
Markdown
## stacks
|
|
|
|
|
|
<br>
|
|
|
|
* stacks are **last in, first out** structures (LIFO), where the newest element is first one to be removed from the structure.
|
|
* stacks are useful in certain recursive algorithms, where you can push temp data as you recurse, and remove them from the (memory or data structure) stack as you backtrace.
|
|
|
|
|
|
<br>
|
|
|
|
---
|
|
|
|
### some examples in this dir
|
|
|
|
<br>
|
|
|
|
#### `stack.py`
|
|
|
|
<br>
|
|
|
|
```python
|
|
python3 stack.py
|
|
|
|
Testing Stack...
|
|
|
|
Stack: [12, 13, 14, 15, 16, 17, 18, 19, 20]
|
|
Stack size: 9
|
|
Stack peek: 20
|
|
Stack is empty: False
|
|
Stack min: 12
|
|
|
|
Popping...
|
|
20
|
|
19
|
|
18
|
|
17
|
|
16
|
|
Stack: [12, 13, 14, 15]
|
|
```
|