Stacks and queues · 1 of 2
Stack and queue basics
Tell a stack from a queue, use both in code, and solve bracket matching, nested repeats and a running minimum with a stack.
- Stacks The stack operations in C++, Java and Python, then a first application, the nearest smaller element. usaco.guide (opens in a new tab)
- Minimum stack / Minimum queue Min Stack's pairs of a value and the minimum below it, then three ways to keep the minimum of a queue. The third combines the pairs with the two-stack queue. cp-algorithms.com (opens in a new tab)
- collections: deque objects Every deque method with its cost: appends and pops at either end take constant time, while indexing into the middle slows toward linear time. docs.python.org (opens in a new tab)
- std::stack The member functions of std::stack and the container it is built on, std::deque unless you choose another. en.cppreference.com (opens in a new tab)
- Open Data Structures, Chapter 2: Array-Based Lists A stack on an array that doubles when it fills, with the amortized analysis of that resizing, a queue on an array that wraps around its end, and a deque built from two stacks. Parts of this page adapt this chapter’s text, licensed CC BY 2.5 Canada (creativecommons.org/licenses/by/2.5/ca), with changed wording, examples and code. opendatastructures.org (opens in a new tab)