This stack is implemented using a Singly Linked List but could also be implemented using an array. I used a LL since there is no need for array indexes and other array methods.
Operation | Description | Big O | Return Type |
---|---|---|---|
push(value) | Append value to the stack | O(1) | void |
pop() | Pops value off the top of the stack | O(1) | T or null |
peek() | Returns value at the top of the stack | O(1) | T or null |
clear() | Clear the stack | O(1) | void |
isEmpty() | Returns true or false | O(1) | boolean |
size() | Return a length of the stack | O(1) | number |