The Adapter Pattern
`std::stack` wraps around `std::deque`, `std::vector`, or `std::list` (default is `deque`). It disables random access and iteration, enforcing strict LIFO access.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
The C++ Standard Template Library implementation of a LIFO Stack. Like queue, it is a container adapter that restricts underlying structures.
`std::stack` wraps around `std::deque`, `std::vector`, or `std::list` (default is `deque`). It disables random access and iteration, enforcing strict LIFO access.
push(x) adds to the top. pop() removes from the top. top() reads the most recently added element. All operate in O(1) time.
Because the default underlying container is `std::deque`, a `std::stack` allocates memory in chunks rather than relying on a single contiguous block, preventing costly full-array reallocations during massive pushes.