正文

质变STL算法2008-12-05 14:26:00

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

分享到:

copy(first, last, result)
返回result+(last-first),拷贝[first, last)到[result, result + (last - first)),注意这些运算符:*result = *first; ++first, ++result

copy_n(first, n, result)
返回result+n,拷贝[first, first + n)到[result, result + n)

copy_backward(first, last, result)
返回result-(last-first),拷贝[first, last)到[result - (last - first), result)

swap(a, b)
返回void,交换a,b

iter_swap(a, b)
返回void,等同于swap(*a, *b)

swap_ranges(first1, last1, first2)
返回first2+(last1-first1),交换区间[first1, last1),[first2, first2 + (last1 - first1))

transform(first, last, result, op)
返回result+(last-first),对于0 <= n < (last - first),*(result + n) = op(*(first + n))
transform(first1, last1, first2, result, bi)
返回result+(last-first),对于0 <= n < (last1 - first1),*(result + n) = bi(*(first1 + n), *(first2 + n))

replace(first, last, old_value, new_value)
返回void,替换[first, last)中*i == old_value的*i = new_value
replace_if(first, last, pred, new_value)
返回void,替换[first, last)中pred(*i) is true的*i = new_value

replace_copy(first, last, result, old_value, new_value)
返回result+(last-first),对于0 <= n < (last - first),if *(first + n) == old_value then *(result + n) = new_value, otherwise, *(result + n) = *(first + n)

replace_copy_if(first, last, result, pred, new_value)
返回result+(last-first),对于0 <= n < (last - first),if pred(*(first + n)) is true then *(result + n) = new_value, otherwise, *(result + n) = *(first + n)

fill(first, last, value)
返回void,对于i在[first, last)中,*i = value

fill_n(first, n, value)
返回first+n,对于i在[first, first + n)中,*i = value

generate(first, last, gen)
返回void,对于i在[first, last)中,*i = gen()

generate_n(first, n, gen)
返回first+n,对于i在[first, first + n)中,*i = gen()

remove(first, last, value)
返回new_last,删除对于i在[first, last)中*i == value的元素,[first, new_last)为结果,且保证原来有序的值继续有序(稳定的),未定义[new_last, last)的内容

remove_if(first, last, pred)
返回new_last,删除对于i在[first, last)中pred(*i) is true的元素,[first, new_last)为结果,且保证原来有序的值继续有序(稳定的),未定义[new_last, last)的内容

remove_copy(first, last, result, value)
返回result_last,删除对于i在[first, last)中*i == value的元素,[result, result_last)为结果,且保证原来有序的值继续有序(稳定的)

remove_copy_if(first, last, result, pred)
返回result_last,删除对于i在[first, last)中pred(*i) is true的元素,[result, result_last)为结果,且保证原来有序的值继续有序(稳定的)

unique(first, last)
返回new_last,删除i在[first + 1, last)中,*i == *(i - 1)的元素,[first, new_last)为结果
unique(first, last, pred)
返回new_last,删除i在[first + 1, last)中,pred(*i, *(i - 1)) is true的元素,[first, new_last)为结果

unique_copy(first, last, result)
返回result_last,删除i在[first + 1, last)中,*i == *(i - 1)的元素,[result, result_last)为结果
unique_copy(first, last, result, pred)
返回result_last,删除i在[first + 1, last)中,pred(*i, *(i - 1)) is true的元素,[result, result_last)为结果

reverse(first, last)
返回void,翻转[first, last)

reverse_copy(first, last, result)
返回result+(last-first),翻转[first, last)后copy到[result, result + (last - first))

rotate(first, mid, last)
返回result_last=first+(last-mid),视[first, last)为一个环,旋转后从mid开始为新的first,[first, result_last)为原来的[mid, last),[result_last, last)为原来的[first, mid)
【VC2005中返回void】

rotate_copy(first, mid, last, result)
返回result+(last-first),旋转后copy到[result, result + (last - first)),[first, last)不变

random_shuffle(first, last)
返回void,随机洗牌[first, last)

random_sample(first, last, ofirst, olast)
返回ofirst+n,n=min{(last-first), (olast-ofirst)},随机抽样,每个样本只在[first, last)中抽一次

random_sample_n(first, last, out, n)
返回out+m,m=min{(last-first), n},随机抽样
random_sample_n(first, last, out, n, rand)
返回out+m,m=min{(last-first), n},随机抽样,随机函数由rand()指定

partition(first, last, pred)
返回middle,划分[first, last)序列,使i在[first, middle)中pred(*i) is true,而j在[middle, last)中pred(*j) is false

stable_partition(first, last, pred)
返回middle,划分[first, last)序列,使i在[first, middle)中pred(*i) is true,而j在[middle, last)中pred(*j) is false,并且是稳定的

阅读(4097) | 评论(3)


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

评论

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