-
Notifications
You must be signed in to change notification settings - Fork 0
Stack
Hamin Pyo edited this page Aug 23, 2021
·
1 revision
Structure with limited access to data.
L.I.F.O. ( Last In First Out ) Structure
- You keep putting elements on top
- You have easy access to remove or look at the top element
- when you only care about the most recent elements
- the order in which you see & save elements actually matters
-
Push
: when you add an element to a stack
-> O(1)
-
Pop
: when you taken an element off of the stack
-> O(1)
=> All you need here is to look at the top element of the stack!
-
pop()is a given function -
append()is equivalent to a push function
Make your own code instead of using append() since it traverses the whole list, taking O(n)
-> it will take a lot faster if we push/pop from the first element in a linked list!
