Stack
Creating a stack:
will create a stack that stores elements of type <return_type>
. The stack follows the Last In, First Out (LIFO) principle, meaning the last element added is the first one to be removed.
Functions:
Function
Description
O notation
push(x)
Adds the element x of type <return_type>
to the stack.
O(1)
pop()
Removes the lastly added element to the stack (if any) and returns it.
O(1)
top()
Return the lastly added element to the stack (if any).
O(1)
empty()
Check whether the stack is empty, returns a boolean.
O(1)
Example use case:
Last updated