C++ 算法
来自cppreference.com
< cpp
下列函数在<algorithm> 或者 <numeric>中定义,属于stl命名空间(namespace)。
| accumulate | 将一段范围的元素累加 |
| adjacent_difference | 计算一个范围相邻元素的差 |
| adjacent_find | 查找相同的两个相邻元素或者具有某种关系的两个相邻元素 |
| binary_search | 判断在某个范围是否存在某个元素 |
| copy | 把一段范围元素拷贝到另一个位置 |
| copy_backward | 把一段范围元素反向拷贝到另一个位置 |
| count | 返回匹配某个值的元素个数 |
| count_if | 返回满足某个条件的元素个数 |
| equal | 判断两个集合是否相等 |
| equal_range | 查找与某个值相等的一段元素 |
| fill | 将一个值赋给某一范围元素 |
| fill_n | 把某个值赋给某个范围一定数目的元素 |
| find | 在一个给定范围查找某个值 |
| find_end | 在某个范围查找某个元素序列 |
| find_first_of | 查找一组元素中的任意一个 |
| find_if | 查找断言为真的第一个元素 |
| for_each | 将一个函数应用于某个范围的元素 |
| generate | 把一个仿函数的结果保存到一个区间里 |
| generate_n | 保存仿函数 N 次执行结果 |
| includes | 返回真,如果后者是前者的子集 |
| inner_product | compute the inner product of two ranges of elements |
| inplace_merge | merge two ordered ranges in-place |
| is_heap | 判断一个范围的元素是否构成堆 |
| iter_swap | 交换两个迭代器指向的元素 |
| lexicographical_compare | returns true if one range is lexicographically less than another |
| lower_bound | search for the first place that a value can be inserted while preserving order |
| make_heap | 将某个范围元素构造为堆 |
| max | 返回两个元素中较大的元素 |
| max_element | 返回某个范围中最大的元素 |
| merge | 将两段有序元素序列合并成有序序列 |
| min | 返回两个元素中的较小者 |
| min_element | 返回区间内最小的元素 |
| mismatch | 找出两个区间里第一个不同的元素 |
| next_permutation | generates the next greater lexicographic permutation of a range of elements |
| nth_element | put one element in its sorted location and make sure that no elements to its left are greater than any elements to its right |
| partial_sort | 将某个范围的前N个元素排序 |
| partial_sort_copy | copy and partially sort a range of elements |
| partial_sum | compute the partial sum of a range of elements |
| partition | 将某段范围元素分为两组 |
| pop_heap | 将堆的最大元素删除 |
| prev_permutation | generates the next smaller lexicographic permutation of a range of elements |
| push_heap | 在堆中添加一个元素 |
| random_shuffle | randomly re-order elements in some range |
| remove | 删除所有与指定值相同的元素 |
| remove_copy | copy a range of elements omitting those that match a certain value |
| remove_copy_if | create a copy of a range of elements, omitting any for which a predicate is true |
| remove_if | 删除所有断言为真的元素 |
| replace | replace every occurrence of some value in a range with another value |
| replace_copy | copy a range, replacing certain elements with new ones |
| replace_copy_if | copy a range of elements, replacing those for which a predicate is true |
| replace_if | change the values of elements for which a predicate is true |
| reverse | 把区间内元素反序 |
| reverse_copy | create a copy of a range that is reversed |
| rotate | move the elements in some range to the left by some amount |
| rotate_copy | copy and rotate a range of elements |
| search | search for a range of elements |
| search_n | search for N consecutive copies of an element in some range |
| 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 |
| sort | 将某段元素按照递增序排序 |
| sort_heap | 将一个堆排序 |
| stable_partition | divide elements into two groups while preserving their relative order |
| stable_sort | 稳定的排序 |
| swap | swap the values of two objects |
| swap_ranges | swaps two ranges of elements |
| transform | applies a function to a range of elements |
| unique | 删除连续重复出现的元素 |
| unique_copy | creates a copy of some range of elements that contains no consecutive duplicates |
| upper_bound | searches for the last place that a value can be inserted while preserving order (first place that is greater than the value) |