You are on page 1of 4

# Algorithms library

The algorithms library denes functions for a variety of purpos es (e.g. s earching, s orting, counting,
manipulating) that operate on ranges of elements . Note that a range is dened as [first, last)where
lastrefers to the element past the las t element to ins pect or modify.

## Non-modifying sequence operations

all_of (C++11)
any_of (C++11)
none_of(C++11)
for_each
count
count_if
mismatch
equal
find

find_if

find_if_not(C++11)
find_end
find_first_of

## checks if a predicate is true for all, any or none of the elements in a

range
(func tion template)

## applies a function to a range of elements

(func tion template)

## returns the number of elements s atis fying s pecic criteria

(func tion template)

## nds the rs t pos ition where two ranges dier

(func tion template)

## determines if two s ets of elements are the s ame

(func tion template)

## nds the rs t element s atis fying s pecic criteria

(func tion template)

## nds the las t s equence of elements in a certain range

(func tion template)

## s earches for any one of a s et of elements

(func tion template)

nds the rs t two adjacent items that are equal (or s atis fy a given
predicate)
(func tion template)

search
search_n

## s earches for a range of elements

(func tion template)

## s earches for a number cons ecutive copies of an element in a range

(func tion template)

## Modifying sequence operations

copy

copy_if(C++11)
copy_n(C++11)
copy_backward
move(C++11)
move_backward(C++11)
fill
fill_n
transform
generate
generate_n

## copies a range of elements to a new location

(func tion template)

## copies a number of elements to a new location

(func tion template)

## copies a range of elements in backwards order

(func tion template)

## moves a range of elements to a new location

(func tion template)

## moves a range of elements to a new location in backwards order

(func tion template)

## as s igns a range of elements a certain value

(func tion template)

## as s igns a value to a number of elements

(func tion template)

## applies a function to a range of elements

(func tion template)

## s aves the res ult of a function in a range

(func tion template)

## s aves the res ult of N applications of a function

(func tion template)

remove
remove_if

remove_copy
remove_copy_if

replace
replace_if

## (func tion template)

(func tion template)

replaces all values s atis fying s pecic criteria with another value
(func tion template)

## copies a range, replacing elements s atis fying s pecic criteria with

another value
(func tion template)

replace_copy
replace_copy_if
swap
swap_ranges
iter_swap
reverse
reverse_copy
rotate
rotate_copy

## s waps the values of two objects

(func tion template)

## s waps two ranges of elements

(func tion template)

## s waps the elements pointed to by two iterators

(func tion template)

## revers es the order of elements in a range

(func tion template)

## creates a copy of a range that is revers ed

(func tion template)

## rotates the order of elements in a range

(func tion template)

## copies and rotate a range of elements

(func tion template)

## random_shuffle(until C++17) randomly re-orders elements in a range

(func tion template)
shuffle
(C++11)
removes cons ecutive duplicate elements in a range
unique
(func tion template)
unique_copy

## creates a copy of s ome range of elements that contains no cons ecutive

duplicates
(func tion template)

Partitioning operations

is_partitioned(C++11)
partition
partition_copy(C++11)
stable_partition
partition_point(C++11)

## determines if the range is partitioned by the given predicate

(func tion template)

## divides a range of elements into two groups

(func tion template)

## copies a range dividing the elements into two groups

(func tion template)

divides elements into two groups while pres erving their relative order
(func tion template)

## locates the partition point of a partitioned range

(func tion template)

Sorting operations

is_sorted(C++11)
is_sorted_until(C++11)
sort
partial_sort
partial_sort_copy
stable_sort

## checks whether a range is s orted into as cending order

(func tion template)

## nds the larges t s orted s ubrange

(func tion template)

## s orts a range into as cending order

(func tion template)

## s orts the rs t N elements of a range

(func tion template)

## copies and partially s orts a range of elements

(func tion template)

## s orts a range of elements while pres erving order between equal

elements
(func tion template)

nth_element

partially s orts the given range making s ure that it is partitioned by the
given element
(func tion template)

## Binary search operations (on sorted ranges)

lower_bound
upper_bound
binary_search
equal_range
Set operations (on sorted ranges)

returns an iterator to the rs t element not less than the given value
(func tion template)

## returns an iterator to the rs t element greater than a certain value

(func tion template)

## determines if an element exis ts in a certain range

(func tion template)

## returns range of elements matching a s pecic key

(func tion template)

merge
inplace_merge
includes
set_difference
set_intersection

## merges two s orted ranges

(func tion template)

## merges two ordered ranges in-place

(func tion template)

## returns true if one s et is a s ubs et of another

(func tion template)

## computes the dierence between two s ets

(func tion template)

## computes the inters ection of two s ets

(func tion template)

## computes the s ymmetric dierence between two s ets

set_symmetric_difference (func tion template)
computes the union of two s ets
set_union
(func tion template)
Heap operations

is_heap(C++11)
is_heap_until(C++11)
make_heap
push_heap
pop_heap
sort_heap

## checks if the given range is a max heap

(func tion template)

## nds the larges t s ubrange that is a max heap

(func tion template)

## creates a max heap out of a range of elements

(func tion template)

## adds an element to a max heap

(func tion template)

## removes the larges t element from a max heap

(func tion template)

## turns a max heap into a range of elements s orted in as cending order

(func tion template)

Minimum/maximum operations

max
max_element
min
min_element
minmax(C++11)
minmax_element(C++11)

## returns the greater of the given values

(func tion template)

## returns the larges t element in a range

(func tion template)

## returns the s maller of the given values

(func tion template)

## returns the s malles t element in a range

(func tion template)

## returns the larger and the s maller of two elements

(func tion template)

## returns the s malles t and the larges t element in a range

(func tion template)

## returns true if one range is lexicographically les s than another

lexicographical_compare (func tion template)
determines if a s equence is a permutation of another s equence
is_permutation(C++11)
(func tion template)
next_permutation

## generates the next greater lexicographic permutation of a range of

elements
(func tion template)

prev_permutation

## generates the next s maller lexicographic permutation of a range of

elements
(func tion template)

Numeric operations

iota(C++11)
accumulate
inner_product
partial_sum

## lls a range with s ucces s ive increments of the s tarting value

(func tion template)

## s ums up a range of elements

(func tion template)

## computes the inner product of two ranges of elements

(func tion template)

## computes the dierences between adjacent elements in a range

(func tion template)

## computes the partial s um of a range of elements

(func tion template)

C library

qsort
bsearch

(func tion)

(func tion)