Stack (LIFO)

Applies to: general

A stack is a last-in, first-out (LIFO) collection: you push onto the top and pop from the top. It models nested structure, function calls use the call stack, and it powers depth-first traversal and expression evaluation.

push 1, push 2, push 3   ->  top is 3
pop -> 3,  pop -> 2       ->  LIFO order

See also: queue, recursion