Module 6 · stack and queue: Last In First Out, First In First Out
Every stack and queue Operation, One by One, With Its Cost
Free with an accountReading
Bob keeps his undo history in a stack<int> of change numbers, and today he wants to print it. He writes the loop that worked on every vector and deque: for (int x : s). GCC 12 refuses with error: no matching function for call to 'begin(std::stack<int>&)'. A stack has no way to walk through its elements, and that is on purpose. This lesson lists every call the two adaptors do have, each with its cost, and then everything they refuse, Bob's loop first.
Checking what this lesson needs for you…
What is inside Every stack and queue Operation, One by One, With Its Cost
- stack: making one
- stack: push and emplace
- stack: top
- stack: pop
- stack: size and empty
- stack: swap
- stack: == and <
- queue: making one
- queue: push and emplace
- queue: front and back
- queue: pop
- queue: size, empty, swap, == and <
- What neither adaptor has
- Emptying one: three ways
- Printing one: pop a copy
- Every cost in one table, and the measurement