You are on page 1of 2

Algorithm Description

find Searches for the first element in the range that matches
the specified value
find_if Searches for the first element in a range that satisfies
the specified condition
find_end Searches for the last occurrence of a particular subrange
in a supplied range
find_first_of Searches for the first occurrence of any element supplied
in one range within a target range; or, in an overloaded
version, searches for the first occurrence of an element
that satisfies a supplied find criterion
adjacent_find Searches for two elements in a collection that are either
equal or satisfy a supplied condition
Comparison Algorithms
equal Compares two elements for equality or uses a specified
binary predicate to determine the same
mismatch Locates the first difference position in two ranges of
elements using a specified binary predicate
lexicographical_compare Compares the elements between two sequences to determine which is the
lesser of the two

Mutating Algorithms
Mutating algorithms are those that change the contents or the order of the sequence they
are operating on. Some of the most useful mutating algorithms supplied by STL are
shown in Table 23.2.
TABLE 23.2 A Quick Reference of Mutating Algorithms
Algorithm Description
Initialization Algorithms
fill Assigns the specified value to every element in the specified
range.
fill_n Assigns the specified value to the first n elements in the specified
range.
generate Assigns the return value of a specified function object to each element in the supplied
range.
generate_n Assigns the value generated by a function to a specified count of
values in a specified range.
Classification of STL Algorithms 545

23
www.it-ebooks.info
ptg7987094
TABLE 23.2 Continued
Algorithm Description
Modifying Algorithms
for_each Performs an operation on every element in a range. When the
specified argument modifies the range, for_each becomes a
mutating algorithm.
transform Applies a specified unary function on every element in the specified range.
Copy Algorithms
copy Copies one range into another.
copy_backward Copies one range into another, arranging elements in the destination range in the
reverse order.
Removal Algorithms
remove Removes an element of a specified value from a specified range.
remove_if Removes an element that satisfies a specified unary predicate
from a specified range.
remove_copy Copies all elements from a source range to a destination range,
except those of a specified value.

remove_copy_if Copies all elements from a source range to a destination range

except those that satisfy a specified unary predicate.


unique Compares adjacent elements in a range and removes the following
duplicates. An overloaded version works using a binary predicate.
unique_copy Copies all but adjacent duplicate elements from a specified source
range to a specified destination range.
Replacement Algorithms
replace Replaces every element in a specified range that matches a
specified value by a replacement value.
replace_if Replaces every element in a specified range that matches
a specified value by a replacement value.
Sort Algorithms
sort Sorts elements in a range using a specified sort criterion, which is
a binary predicate that supplies a strict-weak-ordering. sort might
change relative positions of equivalent elements.
stable_sort Stable sort is similar to sort but preserves order, too.
partial_sort Sorts a specified number of elements in a range.
partial_sort_copy Copies elements from a specified source range to a destination
range that holds them in a sort order.

You might also like