非修改性序列操作:
|
all_of |
Test condition on all elements in range |
|
any_of |
Test if any element in range fulfills condition |
|
|
none_of |
Test if no elements fulfill condition |
|
|
循环 |
for_each |
Apply function to range |
对序列中每个元素执行某项操作 |
查找 |
find |
Find value in range |
在序列中找出某个值第一次出现的位置 |
find_if |
Find element in range |
在序列中找出符合某谓词的第一个元素 |
|
find_if_not |
Find element in range (negative condition) |
|
|
find_end |
Find last subsequence in range |
在序列中找出子子序列的最后一次出现的位置 |
|
find_first_of |
Find element from set in range |
在序列中找出第一次出现指定值集中之值的位置 |
|
adjacent_find |
Find equal adjacent elements in range |
在序列中找出相邻的一对值 |
|
计数 |
count |
Count appearances of value in range |
在序列中统计某个值出现的次数 |
count_if |
Return number of elements in range satisfying condition |
在序列中统计与某谓词匹配的次数 |
|
比较 |
mismatch |
Return first position where two ranges differ |
找出两个序列相异的第一个元素 |
equal |
Test whether the elements in two ranges are equal |
两个序列中对应元素都相同时为真 |
|
is_permutation |
Test whether range is permutation of another |
|
|
搜索 |
search |
Search range for subsequence |
在序列中找出一个子序列的第一次出现的位置 |
search_n |
Search range for elements |
在序列中找出一值连续N次出现的位置 |
修改性序列操作:
复制 |
copy |
Copy range of elements |
从序列的第一个元素起进行复制 |
copy_n |
Copy elements |
|
|
copy_if |
Copy certain elements of range |
|
|
copy_backward |
Copy range of elements backward |
从序列的最后一个元素进行复制 |
|
|
move |
Move range of elements |
|
move_backward |
Move range of elements backward |
|
|
交换 |
swap |
Exchange values of two objects |
交换两个元素 |
swap_ranges |
Exchange values of two ranges |
交换指定范围的元素 |
|
iter_swap |
Exchange values of objects pointed by two iterators |
交换由迭代器所指的两个元素 |
|
变换 |
transform |
Transform range |
将某操作应用于指定范围的每个元素 |
替换 |
replace |
Replace value in range |
用一个给定值替换一些值 |
replace_if |
Replace values in range |
替换满足谓词的一些元素 |
|
replace_copy |
Copy range replacing value |
复制序列时用一给定值替换元素 |
|
replace_copy_if |
Copy range replacing value |
复制序列时替换满足谓词的元素 |
|
填充 |
fill |
Fill range with value |
用一给定值取待所有元素 |
fill_n |
Fill sequence with value |
用一给给定值取待前N个元素 |
|
生成 |
generate |
Generate values for range with function |
用一操作的结果取待所有元素 |
generate_n |
Generate values for sequence with function |
用一操作的结果取待前N个元素 |
|
删除 |
remove |
Remove value from range |
删除具有给定值的元素 |
remove_if |
Remove elements from range |
删除满足谓词的元素 |
|
remove_copy |
Copy range removing value |
复制序列时删除具有给定值的元素 |
|
remove_copy_if |
Copy range removing values |
复制序列时删除满足谓词的元素 |
|
唯一 |
unique |
Remove consecutive duplicates in range |
删除相邻的重复元素 |
unique_copy |
Copy range removing duplicates |
复制序列时删除相邻的重复元素 |
|
反转 |
reverse |
Reverse range |
反转元素的次序 |
reverse_copy |
Copy range reversed |
复制序列时反转元素的次序 |
|
环移 |
rotate |
Rotate left the elements in range |
循环移动元素 |
rotate_copy |
Copy range rotated left |
复制序列是循环移动元素 |
|
随机 |
random_shuffle |
Randomly rearrange elements in range |
采用均匀分布来随机移动元素 |
|
shuffle |
Randomly rearrange elements in range using generator |
|
划分:
|
is_partitioned |
Test whether range is partitioned |
|
partition |
Partition range in two |
将满足某谓词的元素都放到前面 |
|
stable_partition |
Partition range in two - stable ordering |
将满足某谓词的元素都放到前面并维持原顺序 |
|
partition_copy |
Partition range into two |
|
|
partition_point |
Get partition point |
|
排序:
|
sort |
Sort elements in range |
以很好的平均效率排序 |
stable_sort |
Sort elements preserving order of equivalents |
排序,并维持相同元素的原有顺序 |
|
partial_sort |
Partially sort elements in range |
将序列的前一部分排好序 |
|
partial_sort_copy |
Copy and partially sort range |
|
|
is_sorted |
Check whether range is sorted |
|
|
is_sorted_until |
Find first unsorted element in range |
|
|
nth_element |
Sort element in range |
将第N个元素放到它正确的位置 |
二分检索:(使用下面算法时,容器需要先sort排序)
|
lower_bound |
Return iterator to lower bound |
找到大于等于某值的第一次出现 |
upper_bound |
Return iterator to upper bound |
找到大于某值的第一次出现 |
|
equal_range |
Get subrange of equal elements |
找到(在不破坏顺序的前提下)可插入给定值的最大范围 |
|
binary_search |
Test if value exists in sorted sequence |
在有序序列中确定给定元素是否存在 |
集合算法:
归并 |
merge |
Merge sorted ranges |
归并两个有序序列 |
inplace_merge |
Merge consecutive sorted ranges |
归并两个接续的有序序列 |
|
序结构上的集合操作 |
includes |
Test whether sorted range includes another sorted range |
一序列为另一个序列的子序列时为真 |
set_union |
Union of two sorted ranges |
构造两个集合的有序并集 |
|
set_intersection |
Intersection of two sorted ranges |
构造两个集合的有序交集 |
|
set_difference |
Difference of two sorted ranges |
构造两个集合的有序差集 |
|
set_symmetric_difference |
Symmetric difference of two sorted ranges |
构造两个集合的有序对称差集(并-交) |
堆:
|
push_heap |
Push element into heap range |
向堆中加入元素 |
pop_heap |
Pop element from heap range |
从堆中弹出元素 |
|
make_heap |
Make heap from range |
从序列构造堆 |
|
sort_heap |
Sort elements of heap |
给堆排序 |
|
is_heap |
Test if range is heap |
|
|
is_heap_until |
Find first element not in heap order |
|
最大小值计算:
|
min |
Return the smallest |
|
max |
Return the largest |
|
|
minmax |
Return smallest and largest elements |
|
|
min_element |
Return smallest element in range |
|
|
max_element |
Return largest element in range |
|
|
minmax_element |
Return smallest and largest elements in range |
|
其他:
|
lexicographical_compare |
Lexicographical less-than comparison |
|
next_permutation |
Transform range to next permutation |
|
|
prev_permutation |
Transform range to previous permutation |
|
如果有《C++ Primer》的可以参考“附录——算法简介”里也有简单介绍。
参考资料:
1. <algorithm> - C++ Reference