- Define what a stack is
- Understand use cases for a stack
- Implement operations on a stack data structure
-
A LIFO (Last In First Out) data structure!
-
The last element added to the stack will be the first element removed from the stack.
-
👻 Analogy: Think about a stack of plates, or a stack of markers, or a stack of....anything. As you pile it up the last thing (or the topmost thing) is what gets removed first.*
-
Check out Visualgo.net, click Stack to see the visualization.
- Managing function invocations. (Like Call stack in recursion)
- Undo / Redo.
- Routing (the history object) is treated like a stack!
- Stacks are a LIFO data structure where the last value in is always the first one out.
- Stacks are used to handle function invocations (the call stack), for operations like undo/redo, and for - routing (remember pages you have visited and go back/forward) and much more!
- They are not a built in data structure in JavaScript, but are relatively simple to implement.
- Insert and remove are both O(1)


