std::stack
Explanation
LIFO (Last In, First Out). Uses std::deque internally.
See std::stack.
Time complexity:
| Operation | Complexity |
|---|---|
push() | O(1) |
pop() | O(1) |
empty(), size() | O(1) |
Code
#include <print>
#include <stack>
int main() {
std::stack<uint64_t> callStack;
callStack.push(0x1000);
callStack.push(0x2000);
callStack.push(0x3000);
while (!callStack.empty()) {
std::println("Return to: {:#x}", callStack.top());
callStack.pop();
}
return 0;
}
Output
$ ./src/data-structures/build/std-stack
Return to: 0x3000
Return to: 0x2000
Return to: 0x1000