STL中部分算法的英文说明

本文详细介绍了泛型编程中几种重要的非修改序列操作和修改序列操作,包括查找、替换、排序等函数的使用方法及注意事项,帮助读者更好地理解和运用这些函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

these several tens generic functions is very important in generic programming.
so we should understand and be familiar with them,and use them as possible as you can.
 
non-modifying sequence operations:
<for_each>:apply function fo range.
<find>:find value in range.if find the value,stop and return the item's inputeriterator,else return last.
<find_if>:find element in range,but not means the condition is equal,you decide.
<find_end>:find last subsequence in range,two overload,if you dont write the condition ,means equal.
<find_first_of>:find element from set in range.as above find_end,just here is first_of.
<adjacent_find>:find equal adjacent elements in range,and return the first item's iterator.
<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.also you can decide the condition by youself.
<equal>:test whether the elements in two ranges are equal.dont consider the elements if second is long
            so judge two range is complete the same,you should judge first.size()==second.size().
<search>:find subsequence in range,and return the first,also you can write the condition function.
<search_n>:find succession of equal values in range.like search,but here the subsequence should appearant
                 n times,and return the first values' iterator.
 these functions always return the last iterator when search or find a value failure.
 
modifying sequence operations:
<copy>:copy range of elements.copy input to output iterator,and return the next of output's last iterator.
<copy_backward>:copy range of elements backwards.such as copy,but first copy last,copy first at last.
<swap>:exchange values of two objects.the arguments are passed by reference.
<swap_ranges>:exchange values of two ranges.it needs three forwarditerators,first,last,begin.
                      return the second iterator's last exchanged value's next value.
<iter_swap>:exchange values of objects pointed by two iterators.
<transform>:apply function to range.two kinds of overloads,first we can use a unaryoperation,so just need
                 first,last,result,and unaryoperation.else we use a binaryoperation,just add second first argument.
<replace>:replace value in range.replace old value by new value between first and last forwarditerator,return void.
<replace_if>:replace all the values that fill the predicate with new value.
<replace_copy>:copy range replacing value.it doesnt change the value original,but copy the new sequence value
                       to another outputiterator,and return the next of the outputiterator' last.
<replace_copy_if>:oh,you can guess the meaning...
<unique>:remove consecutive duplicates in range.if the value is same,just keep the first one,but after this,the end
             of the sequence will reserve the old value.it returns forwarditerator the next of the end of new sequence.
<unique_copy>:copy range removing duplicates.also can use binaryoperation decide the condition.
<reverse>:reverse range.the arguments is two bidirectionaliterators.
<reverse_copy>:copy range reversed.
<rotate>:rotate elements in range.arguments,first,middle,last,the middle become first position.
             [first,middle) at the end.
<rotate_copy>:
<random_shuffle>:rearrange elements in range randomly.arguments is randomaccessiterator.
<partition>:partition range in two.
<stable_partition>:devide range in two groups - stable ordering.
 
sorting:
<sort>:sort elements in range.it must be randomaccessable iterator,you can decide the compare function.
<stable_sort>:just stable compare to above.
<partial_sort>:partial sort elements in range.[first,middle) is sorted,others not.
<partial_sort_copy>:in the condition partial sort,and copy the whole or a part of elements to another iterators
 
binary search:
<lower_bound>:return iterator to lower bound.return first iterator greater or equal to value
<upper_bound>:return iterator to upper bound.return first iterator greater to value.
<equal_range>:get subrange of equal elements.return a pair of iterator first is lower_bound,sec is upper_bound
<binary_search>:test if value exists in sorted array.return true or false.
to be continued......
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值