正文

SortingSTL算法2008-12-15 15:05:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/rickone/39918.html

分享到:

sort(first, last)
返回void,对[first, last)排序,要求随机访问迭代器
sort(first, last, comp)
返回void,对[first, last)排序,要求随机访问迭代器,使用comp比较(下略)

stable_sort(first, last)
返回void,稳定的排序,对于相等的元素排序前和排序后不会改变先后关系
stable_sort(first, last, comp)

partial_sort(first, mid, last)
返回void,局部排序,选最小的(mid-first)个元素放在有序的[first, mid)中,[mid, last)中的剩余元素顺序未定义
partial_sort(first, mid, last, comp)

partial_sort_copy(first, last, rfirst, rlast)
返回rfirst+n,n=min{(last-first), (rlast-rfirst)},从[first, last)中选最小的n个元素放在[rfirst, rlast)中
partial_sort_copy(first, last, rfirst, rlast, comp)

is_sorted(first, last)
返回bool,true当[first, last)为升序,否则false
is_sorted(first, last, comp)

nth_element(first, nth, last)
返回void,相当于一次划分,以nth大元素为pivot的一次partition,其中[first, nth)中不存在元素i,*nth < *i,[nth, last)中不存在元素j,*j < *nth,他们中的元素不保证有序
nth_element(first, nth, last, comp)

lower_bound(first, last, value)
返回最远的i,使对于j在[first, i)中 *j < value is true
lower_bound(first, last, value, comp)

upper_bound(first, last, value)
返回最远的i,使对于j在[first, i)中 value < *j is false
upper_bound(first, last, value, comp)

equal_range(first, last, value)
返回make_pair(lower_bound(...), upper_bound(...))
equal_range(first, last, value, comp)

binary_search(first, last, value)
返回bool,true当[first, last)中存在value,否则false
binary_search(first, last, value, comp)

merge(first1, last1, first2, last2, result)
返回result + (last1 - first1) + (last2 - first2),归并[first1, last1)和[first2, last2)
merge(first1, last1, first2, last2, result, comp)

inplace_merge(first, mid, last)
返回void,就地归并[first, mid)和[mid, last)为[first, last)
inplace_merge(first, mid, last, comp)

includes(first1, last1, first2, last2)
返回bool,true当[first2, last2)包含在[first1, last1)中,否则false
includes(first1, last1, first2, last2, comp)

set_union(first1, last1, first2, last2, result)
返回result+n,n个联合后的元素,联合不同于归并,相同的元素只联合一次
set_union(first1, last1, first2, last2, result, comp)

set_intersection(first1, last1, first2, last2, result)
返回result+n,n个求交后的元素,对[first1, last1)和[first2, last2)求集合交集
set_intersection(first1, last1, first2, last2, result, comp)

set_difference(first1, last1, first2, last2, result)
返回result+n,n个求差后的元素,对[first1, last1)和[first2, last2)求集合差
set_difference(first1, last1, first2, last2, result, comp)

set_symmetric_difference(first1, last1, first2, last2, result)
返回result+n,n个运算后的元素,对A=[first1, last1),B=[first2, last2),结果为(A-B)并(B-A)
set_symmetric_difference(first1, last1, first2, last2, result, comp)

push_heap(first, last)
返回void,将*(last - 1)压入堆[first, last - 1)中,前提是[first, last - 1) is_heap
push_heap(first, last, comp)

pop_heap(first, last)
返回void,将最大的元素pop到*(last - 1),[first, last - 1)仍然 is_heap,前提是[first, last) is_heap
pop_heap(first, last, comp)

make_heap(first, last)
返回void,生成一个堆[first, last)
make_heap(first, last, comp)

sort_heap(first, last)
返回void,对一个堆排序,前提是[first, last) is_heap
sort_heap(first, last, comp)

is_heap(first, last)
返回bool,true如果[first, last)是堆,否则false
is_heap(first, last, comp)

min(a, b)
min(a, b, comp)
max(a, b)
max(a, b, comp)

min_element(first, last)
返回i,区间[first, last)中最小
min_element(first, last, comp)

max_element(first, last)
返回i,区间[first, last)中最大
max_element(first, last, comp)

lexicographical_compare(first1, last1, first2, last2)
返回bool,true如果[first1, last1)按字典序列小于[first2, last2)
lexicographical_compare(first1, last1, first2, last2, comp)

lexicographical_compare_3way(first1, last1, first2, last2)
返回int,它是strcmp()的泛型,返回3种结果表示三种关系,小于,等于和大于。

next_permutation(first, last)
返回bool,true如果下一个排列存在,否则false,计算下一个排列
next_permutation(first, last, comp)

prev_permutation(first, last)
返回bool,true如果上一个排列存在,否则false,计算上一个排列
prev_permutation(first, last, comp)

阅读(5263) | 评论(3)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册