C++ STL Functions Cheat Sheet
1. Algorithm Functions
- sort(v.begin(), v.end()): Sorts the vector.
- reverse(v.begin(), v.end()): Reverses the vector.
- max(a, b) / min(a, b): Returns max/min of two values.
- max_element(v.begin(), v.end()): Returns iterator to max.
- min_element(v.begin(), v.end()): Returns iterator to min.
- count(v.begin(), v.end(), x): Counts occurrences of x.
- find(v.begin(), v.end(), x): Finds the first occurrence.
- binary_search(v.begin(), v.end(), x): Checks existence (sorted only).
- lower_bound(v.begin(), v.end(), x): First position >= x.
- upper_bound(v.begin(), v.end(), x): First position > x.
- next_permutation(v.begin(), v.end()): Next permutation.
- prev_permutation(v.begin(), v.end()): Previous permutation.
- all_of(v.begin(), v.end(), pred): True if all satisfy pred.
- any_of(v.begin(), v.end(), pred): True if any satisfy pred.
- none_of(v.begin(), v.end(), pred): True if none satisfy pred.
- for_each(v.begin(), v.end(), func): Applies func to each.
2. Numeric Functions
- accumulate(v.begin(), v.end(), 0): Sum of all elements.
- iota(v.begin(), v.end(), start): Fills with increasing values.
3. Heap Functions
- make_heap(v.begin(), v.end()): Converts to a heap.
- push_heap(v.begin(), v.end()): Pushes new element and maintains heap.
- pop_heap(v.begin(), v.end()): Moves largest to end.
- sort_heap(v.begin(), v.end()): Sorts heap.
- is_heap(v.begin(), v.end()): Checks if it's a heap.
4. Set Operations (on sorted containers)
C++ STL Functions Cheat Sheet
- set_union(a, b, out): Union of two sorted ranges.
- set_intersection(a, b, out): Common elements.
- set_difference(a, b, out): Elements in A not in B.
- set_symmetric_difference(a, b, out): Elements in A or B, but not both.