Minimum stack (source code)

= Minimum stack

A <stack> supporting access to its <minimum> in constant <time complexity> when its contents are nonempty. Each <linked list node> stores its value and the minimum of the suffix beginning there. Pushing computes one new cached minimum; popping reveals the previous cached minimum. Keeping one cached value per node handles repeated minima without a special case.