0% found this document useful (0 votes)
223 views2 pages

STL CheatSheet CPP

This document is a cheat sheet for C++ Standard Template Library (STL) functions, categorized into algorithm functions, numeric functions, heap functions, and set operations. It provides a concise list of commonly used functions along with their descriptions, such as sorting, searching, and manipulating data structures. The cheat sheet serves as a quick reference for developers working with C++ STL.

Uploaded by

jjksukuna9968
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
223 views2 pages

STL CheatSheet CPP

This document is a cheat sheet for C++ Standard Template Library (STL) functions, categorized into algorithm functions, numeric functions, heap functions, and set operations. It provides a concise list of commonly used functions along with their descriptions, such as sorting, searching, and manipulating data structures. The cheat sheet serves as a quick reference for developers working with C++ STL.

Uploaded by

jjksukuna9968
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like