C++ STL Cheat Sheet
Sequence Containers
vector: Dynamic array. Access O(1), Insert End O(1)*
list: Doubly linked list. Insert/Delete O(1) anywhere, Access O(n)
deque: Double-ended queue. Insert/Delete at both ends O(1)
array: Fixed-size array. Fast, limited to static size
forward_list: Singly linked list. Efficient front insert/delete
Associative Containers
set: Unique sorted elements. O(log n) insert/search
multiset: Sorted with duplicates. O(log n)
map: Key-value pairs, unique keys. O(log n)
multimap: Key-value pairs, duplicate keys. O(log n)
Unordered Containers
unordered_set/map: Use hash tables. Average O(1) insert/search, not sorted.
unordered_multiset/multimap: Allow duplicates, hash-based
Container Adapters
stack: LIFO. push, pop, top in O(1)
queue: FIFO. push, pop, front/back in O(1)
priority_queue: Max-heap. O(log n) insert/remove, O(1) top
Common Algorithms
sort(begin, end): Sort range in ascending
find(begin, end, val): Linear search
accumulate(begin, end, init): Sum range
remove(begin, end, val): Remove all val, use with erase
copy, copy_if, transform, reverse: Modify or rearrange
Code Example
vector<int> v = {1, 2, 3};
sort(v.begin(), v.end());
auto it = find(v.begin(), v.end(), 2);
int sum = accumulate(v.begin(), v.end(), 0);
v.erase(remove(v.begin(), v.end(), 2), v.end());
C++ STL Cheat Sheet
Headers
<vector>, <list>, <deque>, <array>, <set>, <map>
<unordered_map>, <unordered_set>, <stack>, <queue>, <algorithm>, <numeric>, <utility>