📜  C++ STL-algorithm

📅  最后修改于: 2020-10-16 07:41:14             🧑  作者: Mango

C++算法功能

该库定义了大量功能,这些功能特别适合一次或在一定范围内用于大量元素。现在让我们直接看一下这些功能。

非修改序列操作:

Function Description
all_of The following function tests a condition to all the elements of the range.
any_of The following function tests a condition to some or any of the elements of the range
none_of The following function checks if none of the elements follow the condition or not.
for_each The function applies an operation to all the elements of the range.
find The function finds a value in the range.
find_if The function finds for an element in the range.
find_if_not The function finds an element in the range but in the opposite way as the above one.
find_end The function is used to return the last element of the range.
find_first_of The function finds for the element that satisfies a condition and occurs at the first.
adjacent_find The function makes a search for finding the equal and adjacent elements in a range.
count The function returns the count of a value in the range.
count_if The function returns the count of values that satisfies a condition.
mismatch The function returns the value in sequence which is the first mismatch.
equal The function is used to check if the two ranges have all elements equal.
is_permutation The function checks whether the range in reference is a permutation of some other range.
search The function searches for the subsequence in a range.
search_n The function searches the range for the occurrence of an element.

修改序列操作

Function Description
copy The function copies the range of elements.
copy_n The function copies n elements of the range
copy_if The function copies the elements of the range if a certain condition is fulfilled.
copy_backward The function copies the elements in a backward order
move The function moves the ranges of elements.
move_backward The function moves the range of elements in the backward order
swap The function swaps the value of two objects.
swap_ranges The function swaps the value of two ranges.
iter_swap The function swaps the values of two iterators under reference.
transform The function transforms all the values in a range.
replace The function replaces the values in the range with a specific value.
replace_if The function replaces the value of the range if a certain condition is fulfilled.
replace_copy The function copies the range of values by replacing with an element.
replace_copy_if The function copies the range of values by replacing with an element if a certain condition is fulfilled.
fill The function fills the values in the range with a value.
fill_n The function fills the values in the sequence.
generate The function is used for the generation of values of the range.
generate_n The function is used for the generation of values of the sequence.
remove The function removes the values from the range.
remove_if The function removes the values of the range if a condition is fulfilled.
remove_copy The function copies the values of the range by removing them.
remove_copy_if The function copies the values of the range by removing them if a condition is fulfilled.
unique The function identifies the unique element of the range.
unique_copy The function copies the unique elements of the range.
reverse The function reverses the range.
reverse_copy The function copies the range by reversing values.
rotate The function rotates the elements of the range in left direction.
rotate_copy The function copies the elements of the range which is rotated left.
random_shuffle The function shuffles the range randomly.
shuffle The function shuffles the range randomly with the help of a generator.

分区

Function Description
is_partitioned The function is used to deduce whether the range is partitioned or not.
partition The function is used to partition the range.
stable_partition The function partitions the range in two stable halves.
partition_copy The function copies the range after partition.
partition_point The function returns the partition point for a range.

排序

Function Description
sort The function sorts all the elements in a range.
stable_sort The function sorts the elements in the range maintaining the relative equivalent order.
partial_sort The function partially sorts the elements of the range.
partial_sort_copy The function copies the elements of the range after sorting it.
is_sorted The function checks whether the range is sorted or not.
is_sorted_until The function checks till which element a range is sorted.
nth_element The functions sorts the elements in the range.

二进制搜索

Function Description
lower_bound Returns the lower bound element of the range.
upper_bound Returns the upper bound element of the range.
equal_range The function returns the subrange for the equal elements.
binary_search The function tests if the values in the range exists in a sorted sequence or not.

合并

Function Description
merge The function merges two ranges that are in a sorted order.
inplace_merge The function merges two consecutive ranges that are sorted.
includes The function searches whether the sorted range includes another range or not.
set_union The function returns the union of two ranges that is sorted.
set_intersection The function returns the intersection of two ranges that is sorted.
set_difference The function returns the difference of two ranges that is sorted.
set_symmetric_difference The function returns the symmetric difference of two ranges that is sorted.

Function Description
push_heap The function pushes new elements in the heap.
pop_heap The function pops new elements in the heap.
make_heap The function is used for the creation of a heap.
sort_heap The function sorts the heap.
is_heap The function checks whether the range is a heap.
is_heap_until The function checks till which position a range is a heap.

最小/最大

Function Description
min Returns the smallest element of the range.
max Returns the largest element of the range.
minmax Returns the smallest and largest element of the range.
min_element Returns the smallest element of the range.
max_element Returns the largest element of the range.
minmax_element Returns the smallest and largest element of the range.

其他功能

Function Description
lexicographical_comapre The function performs the lexicographical less-than comparison.
next_permutation The function is used for the transformation of range into the next permutation.
perv_permutation The function is used for the transformation of range into the previous permutation.