C++ 算法(STL)

C/C++ 参考 >

C++ 算法(STL)

Display all entries for C++ Algorithms on one page, or view entries individually:

accumulate
sum up a range of elements
求和:用初值与指定范围内的元素相加。重载的版本不再做加法,而是传进来的二元操作符被应用到元素上。

adjacent_difference
compute the differences between adjacent elements in a range
创建一个新序列,该序列的每个新值都代表了当前元素与上一个元素的差。重载版本用指定的二元操作计算相邻元素的差。

adjacent_find
finds two items that are adjacent to eachother
在 指定的范围内,查找一对相邻的重复元素,如果找到返回一个 ForwardIterator ,指向这对元素的第一个元素。否则返回 last 。重载版本使用输入的二元操作符代替相等的判断。

binary_search
determine if an element exists in a certain range
折半/二分法查找:在有序序列中查找 value ,如果找到返回 true 。重载的版本使用指定的比较函数对象或者函数指针来判断相等。

copy
copy some range of elements to a new location
复制序列。

copy_backward
copy a range of elements in backwards order
除了元素以相反的顺序被拷贝外,别的和 copy 相同。

copy_n
copy N elements
只复制N个元素。

count
return the number of elements matching a given value
利用等于操作符,把标志范围类的元素与输入的值进行比较,并返回相等元素的个数。

count_if
return the number of elements for which a predicate is true
对于标志范围类的元素,应用输入的操作符,并返回结果为 true 的次数。

equal
determine if two sets of elements are the same
如果两个序列在范围内的元素都相等,则 equal 返回 true 。重载版本使用输入的操作符代替了默认的等于操作符。

equal_range
search for a range of elements that are all equal to a certain element
返回一对 iterator ,第一个 iterator 表示由 lower_bound 返回的 iterator ,第二个表示由 upper_bound 返回的 iterator 值。

fill
assign a range of elements a certain value
填充:将输入的值的拷贝赋给范围内的每个元素。

fill_n
assign a value to some number of elements
填充:将输入的值赋值给 first 到 frist+n 范围内的元素。

find
find a value in a given range
查找:利用底层元素的等于操作符,对范围内的元素与输入的值进行比较。当匹配时,结束搜索,返回该元素的一个 InputIterator 。

find_end
find the last sequence of elements in a certain range
查找:使用输入的函数替代了等于操作符执行了 find 。

find_first_of
search for any one of a set of elements
查找:在范围内查找“由输入的另外一个 iterator 对标志的第二个序列”的最后一次出现。重载版本中使用了用户输入的操作符替代等于操作。

find_if
find the first element for which a certain predicate is true
查找:在范围内查找“由输入的另外一个 iterator 对标志的第二个序列”中的任意一个元素的第一次出现。重载版本中使用了用户自定义的操作符。

for_each
apply a function to a range of elements
依次对范围内的所有元素执行输入的函数。

generate
saves the result of a function in a range
通过对输入的函数 gen 的连续调用来填充指定的范围。

generate_n
saves the result of N applications of a function
填充 n 个元素。

includes
returns true if one set is a subset of another
判断 [first1, last1) 的一个元素是否被包含在另外一个序列中。使用底层元素的 <= 操作符,重载版本使用用户输入的函数。

inner_product
compute the inner product of two ranges of elements
对两个序列做内积 ( 对应的元素相乘,再求和 ) ,并将内积加到一个输入的的初始值上。重载版本使用了用户定义的操作。

inplace_merge
merge two ordered ranges in-place
合并两个排过序的连续序列,结果序列覆盖了两端范围,重载版本使用输入的操作进行排序。

is_heap
returns true if a given range is a heap
判断指定的范围是否是构成一个堆。

is_sorted
returns true if a range is sorted in ascending order
判断指定的范围时候为升序排列。

iter_swap
swaps the elements pointed to by two iterators
交换两个 ForwardIterator 的值。

lexicographical_compare
returns true if one range is lexicographically less than another
比较两个序列(使用less)。重载版本使用了用户自定义的比较操作。

lexicographical_compare_3way
determines if one range is lexicographically less than or greater than another
确定第一个范围的元素,小于或者大于另一个范围的元素。
类似于memcmp的返回规则。

lower_bound
search for the first place that a value can be inserted while preserving order
返回一个 iterator ,它指向在范围内的有序序列中可以插入指定值而不破坏容器顺序的第一个位置。重载函数使用了自定义的比较操作。

make_heap
creates a heap out of a range of elements
把范围内的元素生成一个堆。重载版本使用自定义的比较操作。

max
returns the larger of two elements
返回两个元素中的较大的一个,重载版本使用了自定义的比较操作。

max_element
returns the largest element in a range
返回一个 iterator ,指出序列中最大的元素。重载版本使用自定义的比较操作。

merge
merge two sorted ranges
合并两个有序序列,并存放到另外一个序列中。重载版本使用自定义的比较。

min
returns the smaller of two elements
类似于 max ,不过返回最小的元素。

min_element
returns the smallest element in a range
类似于 max_element ,不过返回最小的元素。

mismatch
finds the first position where two ranges differ
并行的比较两个序列,指出第一个不匹配的位置,它返回一对 iterator ,标志第一个不匹配的元素位置。如果都匹配,返回每个容器的 last 。重载版本使用自定义的比较操作。

next_permutation
generates the next greater lexicographic permutation of a range of elements
取出当前范围内的排列,并将其重新排序为下一个排列。重载版本使用自定义的比较操作。

nth_element
put one element in its sorted location and make sure that no elements to its left are greater than any elements to its right
将范围内的序列重新排序,使所有小于第 n 个元素的元素都出现在它前面,而大于它的都出现在后面,重载版本使用了自定义的比较操作。

partial_sort
sort the first N elements of a range
对整个序列做部分排序,被排序元素的个数正好可以被放到范围内。重载版本使用自定义的比较操作。

partial_sort_copy
copy and partially sort a range of elements
与 partial_sort 相同,除了将经过排序的序列复制到另外一个容器。

partial_sum
compute the partial sum of a range of elements
创建一个新的元素序列,其中每个元素的值代表了范围内该位置之前所有元素之和。重载版本使用了自定义操作替代加法。

partition
divide a range of elements into two groups
对范围内元素重新排序,使用输入的函数,把计算结果为 true 的元素都放在结果为 false 的元素之前。

pop_heap
remove the largest element from a heap
并不是真正的把最大元素从堆中弹出,而是重新排序堆。它把 first 和 last-1 交换,然后重新做成一个堆。可以使用容器的 back 来访问被“弹出“的元素或者使用 pop_back 来真正的删除。重载版本使用自定义的比较操作。

prev_permutation
generates the next smaller lexicographic permutation of a range of elements
取出范围内的序列并将它重新排序为上一个序列。如果不存在上一个序列则返回 false 。重载版本使用自定义的比较操作。

push_heap
add an element to a heap
假设 first 到 last-1 是一个有效的堆,要被加入堆的元素在位置 last-1 ,重新生成堆。在指向该函数前,必须先把元素插入容器后。重载版本使用指定的比较。

random_sample
randomly copy elements from one range to another

random_sample_n
sample N random elements from a range

random_shuffle
randomly re-order elements in some range
对范围内的元素随机调整次序。重载版本输入一个随机数产生操作。

remove
remove elements equal to certain value
删除在范围内的所有等于指定的元素,注意,该函数并不真正删除元素。内置数组不适合使用 remove 和 remove_if 函数。

remove_copy
copy a range of elements omitting those that match a certian value
将所有不匹配的元素都复制到一个指定容器,返回的 OutputIterator 指向被拷贝的末元素的下一个位置。

remove_copy_if
create a copy of a range of elements, omitting any for which a predicate is true
将所有不匹配的元素拷贝到一个指定容器。

remove_if
remove all elements for which a predicate is true
删除所有范围内输入操作结果为 true 的元素。

replace
replace every occurrence of some value in a range with another value
将范围内的所有等于 old_value 的元素都用 new_value 替代。

replace_copy
copy a range, replacing certain elements with new ones
与 replace 类似,不过将结果写入另外一个容器。

replace_copy_if
copy a range of elements, replacing those for which a predicate is true
类似与 replace_if ,不过将结果写入另外一个容器

replace_if
change the values of elements for which a predicate is true
将范围内的所有操作结果为 true 的元素用新值替代。

reverse
reverse elements in some range
将范围内元素重新按反序排列。

reverse_copy
create a copy of a range that is reversed
类似与 reverse ,不过将结果写入另外一个容器。

rotate
move the elements in some range to the left by some amount
将范围内的元素移到容器末尾,由 middle 指向的元素成为容器第一个元素。

rotate_copy
copy and rotate a range of elements
类似与 rotate ,不过将结果写入另外一个容器

search
search for a range of elements
给出了两个范围,返回一个 iterator ,指向在范围内第一次出现子序列的位置。重载版本使用自定义的比较操作。

search_n
search for N consecutive copies of an element in some range
在范围内查找 value 出现 n 次的子序列。重载版本使用自定义的比较操作。

set_difference
computes the difference between two sets
构造一个排过序的序列,其中的元素出现在第一个序列中,但是不包含在第二个序列中。重载版本使用自定义的比较操作。

set_intersection
computes the intersection of two sets
构造一个排过序的序列,其中的元素在两个序列中都存在。重载版本使用自定义的比较操作。

set_symmetric_difference
computes the symmetric difference between two sets
构造一个排过序的序列,其中的元素在第一个序列中出现,但是不出现在第二个序列中。重载版本使用自定义的比较操作。

set_union
computes the union of two sets
构造一个排过序的序列,它包含两个序列中的所有的不重复元素。重载版本使用自定义的比较操作。

sort
sort a range into ascending order
以升序重新排列范围内的元素,重载版本使用了自定义的比较操作。

sort_heap
turns a heap into a sorted range of elements
对范围内的序列重新排序,它假设该序列是个有序的堆。重载版本使用自定义的比较操作。

stable_partition
divide elements into two groups while preserving their relative order
与 partition 类似,不过它保证保留容器中的相对顺序。

stable_sort
sort a range of elements while preserving order between equal elements
类似与 sort ,不过保留相等元素之间的顺序关系。

swap
swap the values of two objects
交换存储在两个对象中的值。

swap_ranges
swaps two ranges of elements
将在范围内的元素与另外一个序列的元素值进行交换。

transform
applies a function to a range of elements
将输入的操作作用在范围内的每个元素上,并产生一个新的序列。重载版本将操作作用在一对元素上,另外一个元素来自输入的另外一个序列。结果输出到指定的容器。

unique
remove consecutive duplicate elements in a range
清除序列中重复的元素,和 remove 类似,它也不能真正的删除元素。重载版本使用了自定义的操作。

unique_copy
create a copy of some range of elements that contains no consecutive duplicates
类似与 unique ,不过它把结果输出到另外一个容器。

upper_bound
searches for the last possible location to insert an element into an ordered range
返回一个 iterator ,它指向在范围内的有序序列中插入 value 而不破坏容器顺序的最后一个位置,该位置标志了一个大于 value 的值。重载版本使用了输入的比较操作。

posted on 2008-09-09 13:31 FongLuo 阅读(378) 评论(0)  编辑 收藏 引用 所属分类: STL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

常用链接

留言簿

随笔分类(11)

随笔档案(79)

文章档案(1)

收藏夹(38)

学习网站

一般网站

最新随笔

搜索

积分与排名

最新评论

阅读排行榜