A LIFO data structure!
The last element added to the stack will be the first element removed from the stack
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.
A series of nodes!
10
2
22
7
last
first
size = 4
The Call Stack!
class Stack {
constructor(){
this.first = null;
this.last = null;
this.size = 0;
}
}
class Node {
constructor(value){
this.value = value;
this.next = null;
}
}
Add a value to the top of the stack!
Remove a value from the top of the stack!
Insertion - O(1)
Removal - O(1)
Searching - O(N)
Access - O(N)