Stack
Last in, first out through one active end
Only the top is exposed
A stack accepts push and pop at the same end. The newest value is therefore the first one removed, a rule known as last in, first out (LIFO). peek reads that value without changing the stack.
Press push to add an item.
An array-backed stack keeps the top at the end of a dynamic array, so push and pop are amortized O(1). A linked implementation can make both operations worst-case O(1) by treating the list head as the top.
Why stacks appear in algorithms
Function calls use a stack to remember return points and local state. Depth-first search uses the same idea explicitly or through recursion. Parsers, expression evaluators, undo history, and monotonic-stack algorithms all rely on controlled access to the most recent unfinished item.
Compare LIFO ordering with the first-in, first-out behavior of a queue.