Translations of this page?:

C++ Algorithms

The following functions are defined in <algorithm>

Non-modifying sequence operations
for_each applies a function to a range of elements
count returns the number of elements matching a given value
count_if returns the number of elements for which a predicate is true
mismatch finds the first position where two ranges differ
equal determines if two sets of elements are the same
find finds a value in a given range
find_if finds the first element for which a certain predicate is true
find_end finds the last sequence of elements in a certain range
find_first_of searches for any one of a set of elements
adjacent_find finds two identical (or some other relationship) items adjacent to each other
search searches for a range of elements
search_n searches for N consecutive copies of an element in some range
Modifying sequence operations
copy copies some range of elements to a new location
copy_backward copies a range of elements in backwards order
fill assigns a range of elements a certain value
fill_n assigns a value to some number of elements
transform applies a function to a range of elements
generate saves the result of a function in a range
generate_n saves the result of N applications of a function
remove removes elements equal to certain value
remove_if removes all elements for which a predicate is true
remove_copy copies a range of elements omitting those that match a certain value
remove_copy_if creates a copy of a range of elements, omitting any for which a predicate is true
replace replaces every occurrence of some value in a range with another value
replace_if changes the values of elements for which a predicate is true
replace_copy copies a range, replacing certain elements with new ones
replace_copy_if copies a range of elements, replacing those for which a predicate is true
swap swaps the values of two objects
swap_ranges swaps two ranges of elements
iter_swap swaps the elements pointed to by two iterators
partition divides a range of elements into two groups
stable_partition divides elements into two groups while preserving their relative order
reverse reverses elements in some range
reverse_copy creates a copy of a range that is reversed
rotate moves the elements in some range to the left by some amount
rotate_copy copies and rotate a range of elements
random_shuffle randomly re-orders elements in some range
unique removes consecutive duplicate elements in a range
unique_copy creates a copy of some range of elements that contains no consecutive duplicates
Sorting operations (on sorted ranges)
sort sorts a range into ascending order
partial_sort sorts the first N elements of a range
partial_sort_copy copies and partially sorts a range of elements
stable_sort sorts a range of elements while preserving order between equal elements
nth_element puts one element in its sorted location and makes sure that no elements to its left are greater than any elements to its right
Binary search operations (on sorted ranges)
lower_bound searches for the first place that a value can be inserted while preserving order
upper_bound searches for the last place that a value can be inserted while preserving order (first place that is greater than the value)
binary_search determines if an element exists in a certain range
equal_range searches for a range of elements that are all equal to a certain element
Set operations (on sorted ranges)
merge merges two sorted ranges
inplace_merge merges two ordered ranges in-place
includes returns true if one set is a subset of another
set_difference computes the difference between two sets
set_intersection computes the intersection of two sets
set_symmetric_difference computes the symmetric difference between two sets
set_union computes the union of two sets
Heap operations
is_heap returns true if a given range is a heap
make_heap creates a heap out of a range of elements
push_heap adds an element to a heap
pop_heap removes the largest element from a heap
sort_heap turns a heap into a sorted range of elements
Minimum/maximum operations
max returns the larger of two elements
max_element returns the largest element in a range
min returns the smaller of two elements
min_element returns the smallest element in a range
lexicographical_compare returns true if one range is lexicographically less than another
next_permutation generates the next greater lexicographic permutation of a range of elements
prev_permutation generates the next smaller lexicographic permutation of a range of elements
Numeric operations

The following functions are defined in <numeric>

accumulate sums up a range of elements
inner_product computes the inner product of two ranges of elements
adjacent_difference computes the differences between adjacent elements in a range
partial_sum computes the partial sum of a range of elements

C library

The following functions are defined in <cstdlib>

qsort sorts a range of elements with unspecified type
bsearch searches an array for an element of unspecified type
 
• • • SitemapRecent changesRSScc