17 lines
956 B
Markdown
17 lines
956 B
Markdown
|
A data-structure often associated with the queue is the stack.
|
||
|
That's because they are basically the opposite of one another.
|
||
|
While the queue works on the FIFO-principle the stack works
|
||
|
on the **LIFO**-principle (**L**ast **i**n **f**irst **o**ut).
|
||
|
|
||
|
Similar two the queue we have three basic operations, but they are called
|
||
|
different to distinguish between the stack and the queue.
|
||
|
- We put something at the top of the stack. That is called push.
|
||
|
- We take something from the top of the stack. That is called pop.
|
||
|
- As with the queue we sometimes one to just take a look at the top of the stack.
|
||
|
So a peak operation is nice, but not necessary
|
||
|
|
||
|
Stacks are useful data-structures for parsing or when you want follow some data to the end
|
||
|
and then back trace to a previous state, like in depth-fist-search.
|
||
|
These are just some use cases for stacks, but they have many more.
|
||
|
|
||
|
Your task is to implement the push, pop and peak functions for the stack.
|