A stack is a set of nodes in which each node refrences the next node, pushing
to stack means to add to it, while popping
removes a node from the stack, peek
in turn calls the top
node in the stack.
Pushing is always O(1) operation, because it just creates a new node and assign it as top node, the next to this new node is the old top
Also an O(1), keep in mind that pop needs to return the popped node, so you have to store it before popping it, this is done by assiging the top to the next of current top, and putiing null
as next of current (old) top.
It is the opposit (in terms of ordering) to stacks, it has its own terminology: