C++ STL库实现了很多常用的算法,基本都在
for_each
为指定序列区间应用函数fn
template
Function for_each (InputIterator first, InputIterator last, Function fn);
find
查找等于指定值的第一个元素位置
template
InputIterator find (InputIterator first, InputIterator last, const T& val);
find_if
查找满足条件的第一个元素位置
template
InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);
find_first_of
在一个序列中查找等于第二个序列中任何一个元素的第一个元素的位置
template
ForwardIterator1 find_first_of (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); t
find_end
在序列1所涵盖的区间中查找序列2最后一次的出现点,如果不存在则返回
template
ForwardIterator1 find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);;
count
返回与value相等的元素个数
template
count (InputIterator first, InputIterator last, const T& val);
count_if
返回满足指定操作的元素的个数
search
在序列1所涵盖的区间中查找序列2的首次出现点,如果不存在则返回
template
ForwardIterator1 search (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);
search_n
找出n个符合条件的元素形成的子序列
transform
transform() 可以将函数应用到序列的元素上,并将这个函数返回的值保存到另一个序列中,它返回的迭代器指向输出序列所保存的最后一个元素的下一个位置。
template
OutputIterator transform (InputIterator first1, InputIterator last1, OutputIterator result, UnaryOperation op);
copy
copy_backward
swap
swap_ranges
互相交换元素
replace
用new_value代替old_value
replace_if
替换满足条件的元素
fill
填充序列
fill_n
填充序列的前n个元素
remove
移除与value相等的元素,并不是真正删除
remove_if
移除被仿函数核定为true的元素,并不是真正删除
remove_copy
移除与value相等的元素,并不是真正删除,结果拷贝到另一处空间
remove_copy_if
移除被仿函数核定为true的元素,并不是真正删除,结果拷贝到另一处空间
unique
移除重复的元素,必须先排序
reverse
颠倒排序
rotate
把[first, middle) 和[middle, last) 的元素互换
random_shuffle
随机重排
sort
不稳定排序
stable_sort
稳定排序
partial_sort
分区排序
partial_sort_copy
分区排序并拷贝
nth_element
使第n小(大)元素排在合适位置
lower_bound
二分查找的下界 (从小到大序列中二分查找第一个大于等于目标数的位置)
upper_bound
二分查找的上届 (从小到大序列中二分查找第一个大于目标数的位置)
equal_bound
二分查找的区间 [下界,上届)
binary_search
二分查找
template
bool binary_search (ForwardIterator first, ForwardIterator last, const T& val);
merge
将两个有序集合s1和s2合并起来置于另一段空间,结果是有序序列
partition
不稳定分割
stable_partition
稳定分割