﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-FongLuo-随笔分类-STL</title><link>http://www.cppblog.com/FongLuo/category/21220.html</link><description>命运负责洗牌,但是玩牌的是我们自己</description><language>zh-cn</language><lastBuildDate>Tue, 07 Jun 2016 12:31:36 GMT</lastBuildDate><pubDate>Tue, 07 Jun 2016 12:31:36 GMT</pubDate><ttl>60</ttl><item><title>C++ 算法(STL)</title><link>http://www.cppblog.com/FongLuo/archive/2008/09/09/61373.html</link><dc:creator>FongLuo</dc:creator><author>FongLuo</author><pubDate>Tue, 09 Sep 2008 05:31:00 GMT</pubDate><guid>http://www.cppblog.com/FongLuo/archive/2008/09/09/61373.html</guid><wfw:comment>http://www.cppblog.com/FongLuo/comments/61373.html</wfw:comment><comments>http://www.cppblog.com/FongLuo/archive/2008/09/09/61373.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/FongLuo/comments/commentRss/61373.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/FongLuo/services/trackbacks/61373.html</trackback:ping><description><![CDATA[<p><a href="http://sites.google.com/site/fongluogoolesite/cc-%E5%8F%82%E8%80%83">C/C++ 参考</a> &gt;  </p><h5>C++ 算法(STL)</h5> <p><a href="http://www.cppreference.com/cppalgorithm/all.html">Display all entries</a> for C++ Algorithms on one page, or view entries individually: </p><p><a href="http://www.cppreference.com/cppalgorithm/accumulate.html">accumulate</a><br /><strong>sum up a range of elements</strong><br />求和：用初值与指定范围内的元素相加。重载的版本不再做加法，而是传进来的二元操作符被应用到元素上。 </p><p><a href="http://www.cppreference.com/cppalgorithm/adjacent_difference.html">adjacent_difference</a><br /><strong>compute the differences between adjacent elements in a range</strong><br />创建一个新序列，该序列的每个新值都代表了当前元素与上一个元素的差。重载版本用指定的二元操作计算相邻元素的差。 </p><p><a href="http://www.cppreference.com/cppalgorithm/adjacent_find.html">adjacent_find</a><br /><strong>finds two items that are adjacent to eachother</strong><br />在 指定的范围内，查找一对相邻的重复元素，如果找到返回一个 ForwardIterator ，指向这对元素的第一个元素。否则返回 last 。重载版本使用输入的二元操作符代替相等的判断。 </p><p><a href="http://www.cppreference.com/cppalgorithm/binary_search.html">binary_search</a><br /><strong>determine if an element exists in a certain range</strong><br />折半/二分法查找：在有序序列中查找 value ，如果找到返回 true 。重载的版本使用指定的比较函数对象或者函数指针来判断相等。 </p><p><a href="http://www.cppreference.com/cppalgorithm/copy.html">copy</a><br /><strong>copy some range of elements to a new location</strong><br />复制序列。 </p><p><a href="http://www.cppreference.com/cppalgorithm/copy_backward.html">copy_backward</a><br /><strong>copy a range of elements in backwards order</strong><br />除了元素以相反的顺序被拷贝外，别的和 copy 相同。 </p><p><a href="http://www.cppreference.com/cppalgorithm/copy_n.html">copy_n</a><br /><strong>copy N elements</strong><br />只复制N个元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/count.html">count</a><br /><strong>return the number of elements matching a given value</strong><br />利用等于操作符，把标志范围类的元素与输入的值进行比较，并返回相等元素的个数。 </p><p><a href="http://www.cppreference.com/cppalgorithm/count_if.html">count_if</a><br /><strong>return the number of elements for which a predicate is true</strong><br />对于标志范围类的元素，应用输入的操作符，并返回结果为 true 的次数。 </p><p><a href="http://www.cppreference.com/cppalgorithm/equal.html">equal</a><br /><strong>determine if two sets of elements are the same</strong><br />如果两个序列在范围内的元素都相等，则 equal 返回 true 。重载版本使用输入的操作符代替了默认的等于操作符。 </p><p><a href="http://www.cppreference.com/cppalgorithm/equal_range.html">equal_range</a><br /><strong>search for a range of elements that are all equal to a certain element</strong><br />返回一对 iterator ，第一个 iterator 表示由 lower_bound 返回的 iterator ，第二个表示由 upper_bound 返回的 iterator 值。 </p><p><a href="http://www.cppreference.com/cppalgorithm/fill.html">fill</a><br /><strong>assign a range of elements a certain value</strong><br />填充：将输入的值的拷贝赋给范围内的每个元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/fill_n.html">fill_n</a><br /><strong>assign a value to some number of elements</strong><br />填充：将输入的值赋值给 first 到 frist+n 范围内的元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/find.html">find</a><br /><strong>find a value in a given range</strong><br />查找：利用底层元素的等于操作符，对范围内的元素与输入的值进行比较。当匹配时，结束搜索，返回该元素的一个 InputIterator 。 </p><p><a href="http://www.cppreference.com/cppalgorithm/find_end.html">find_end</a><br /><strong>find the last sequence of elements in a certain range</strong><br />查找：使用输入的函数替代了等于操作符执行了 find 。 </p><p><a href="http://www.cppreference.com/cppalgorithm/find_first_of.html">find_first_of</a><br /><strong>search for any one of a set of elements</strong><br />查找：在范围内查找&#8220;由输入的另外一个 iterator 对标志的第二个序列&#8221;的最后一次出现。重载版本中使用了用户输入的操作符替代等于操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/find_if.html">find_if</a><br /><strong>find the first element for which a certain predicate is true</strong><br />查找：在范围内查找&#8220;由输入的另外一个 iterator 对标志的第二个序列&#8221;中的任意一个元素的第一次出现。重载版本中使用了用户自定义的操作符。 </p><p><a href="http://www.cppreference.com/cppalgorithm/for_each.html">for_each</a><br /><strong>apply a function to a range of elements</strong><br />依次对范围内的所有元素执行输入的函数。 </p><p><a href="http://www.cppreference.com/cppalgorithm/generate.html">generate</a><br /><strong>saves the result of a function in a range</strong><br />通过对输入的函数 gen 的连续调用来填充指定的范围。 </p><p><a href="http://www.cppreference.com/cppalgorithm/generate_n.html">generate_n</a><br /><strong>saves the result of N applications of a function</strong><br />填充 n 个元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/includes.html">includes</a><br /><strong>returns true if one set is a subset of another</strong><br />判断 [first1, last1) 的一个元素是否被包含在另外一个序列中。使用底层元素的 &lt;= 操作符，重载版本使用用户输入的函数。 </p><p><a href="http://www.cppreference.com/cppalgorithm/inner_product.html">inner_product</a><br /><strong>compute the inner product of two ranges of elements</strong><br />对两个序列做内积 ( 对应的元素相乘，再求和 ) ，并将内积加到一个输入的的初始值上。重载版本使用了用户定义的操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/inplace_merge.html">inplace_merge</a><br /><strong>merge two ordered ranges in-place</strong><br />合并两个排过序的连续序列，结果序列覆盖了两端范围，重载版本使用输入的操作进行排序。 </p><p><a href="http://www.cppreference.com/cppalgorithm/is_heap.html">is_heap</a><br /><strong>returns true if a given range is a heap</strong><br />判断指定的范围是否是构成一个堆。 </p><p><a href="http://www.cppreference.com/cppalgorithm/is_sorted.html">is_sorted</a><br /><strong>returns true if a range is sorted in ascending order</strong><br />判断指定的范围时候为升序排列。 </p><p><a href="http://www.cppreference.com/cppalgorithm/iter_swap.html">iter_swap</a><br /><strong>swaps the elements pointed to by two iterators</strong><br />交换两个 ForwardIterator 的值。 </p><p><a href="http://www.cppreference.com/cppalgorithm/lexicographical_compare.html">lexicographical_compare</a><br /><strong>returns true if one range is lexicographically less than another</strong><br />比较两个序列(使用less)。重载版本使用了用户自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/lexicographical_compare_3.html">lexicographical_compare_3way</a><br /><strong>determines if one range is lexicographically less than or greater than another</strong><br />确定第一个范围的元素，小于或者大于另一个范围的元素。<br />类似于memcmp的返回规则。 </p><p><a href="http://www.cppreference.com/cppalgorithm/lower_bound.html">lower_bound</a><br /><strong>search for the first place that a value can be inserted while preserving order</strong><br />返回一个 iterator ，它指向在范围内的有序序列中可以插入指定值而不破坏容器顺序的第一个位置。重载函数使用了自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/make_heap.html">make_heap</a><br /><strong>creates a heap out of a range of elements</strong><br />把范围内的元素生成一个堆。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/max.html">max</a><br /><strong>returns the larger of two elements</strong><br />返回两个元素中的较大的一个，重载版本使用了自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/max_element.html">max_element</a><br /><strong>returns the largest element in a range</strong><br />返回一个 iterator ，指出序列中最大的元素。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/merge.html">merge</a><br /><strong>merge two sorted ranges</strong><br />合并两个有序序列，并存放到另外一个序列中。重载版本使用自定义的比较。 </p><p><a href="http://www.cppreference.com/cppalgorithm/min.html">min</a><br /><strong>returns the smaller of two elements</strong><br />类似于 max ，不过返回最小的元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/min_element.html">min_element</a><br /><strong>returns the smallest element in a range</strong><br />类似于 max_element ，不过返回最小的元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/mismatch.html">mismatch</a><br /><strong>finds the first position where two ranges differ</strong><br />并行的比较两个序列，指出第一个不匹配的位置，它返回一对 iterator ，标志第一个不匹配的元素位置。如果都匹配，返回每个容器的 last 。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/next_permutation.html">next_permutation</a><br /><strong>generates the next greater lexicographic permutation of a range of elements</strong><br />取出当前范围内的排列，并将其重新排序为下一个排列。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/nth_element.html">nth_element</a><br /><strong>put one element in its sorted location and make sure that no elements to its left are greater than any elements to its right</strong><br />将范围内的序列重新排序，使所有小于第 n 个元素的元素都出现在它前面，而大于它的都出现在后面，重载版本使用了自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/partial_sort.html">partial_sort</a><br /><strong>sort the first N elements of a range</strong><br />对整个序列做部分排序，被排序元素的个数正好可以被放到范围内。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/partial_sort_copy.html">partial_sort_copy</a><br /><strong>copy and partially sort a range of elements</strong><br />与 partial_sort 相同，除了将经过排序的序列复制到另外一个容器。 </p><p><a href="http://www.cppreference.com/cppalgorithm/partial_sum.html">partial_sum</a><br /><strong>compute the partial sum of a range of elements</strong><br />创建一个新的元素序列，其中每个元素的值代表了范围内该位置之前所有元素之和。重载版本使用了自定义操作替代加法。 </p><p><a href="http://www.cppreference.com/cppalgorithm/partition.html">partition</a><br /><strong>divide a range of elements into two groups</strong><br />对范围内元素重新排序，使用输入的函数，把计算结果为 true 的元素都放在结果为 false 的元素之前。 </p><p><a href="http://www.cppreference.com/cppalgorithm/pop_heap.html">pop_heap</a><br /><strong>remove the largest element from a heap</strong><br />并不是真正的把最大元素从堆中弹出，而是重新排序堆。它把 first 和 last-1 交换，然后重新做成一个堆。可以使用容器的 back 来访问被&#8220;弹出&#8220;的元素或者使用 pop_back 来真正的删除。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/prev_permutation.html">prev_permutation</a><br /><strong>generates the next smaller lexicographic permutation of a range of elements</strong><br />取出范围内的序列并将它重新排序为上一个序列。如果不存在上一个序列则返回 false 。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/push_heap.html">push_heap</a><br /><strong>add an element to a heap</strong><br />假设 first 到 last-1 是一个有效的堆，要被加入堆的元素在位置 last-1 ，重新生成堆。在指向该函数前，必须先把元素插入容器后。重载版本使用指定的比较。 </p><p><a href="http://www.cppreference.com/cppalgorithm/random_sample.html">random_sample</a><br /><strong>randomly copy elements from one range to another</strong> </p><p><a href="http://www.cppreference.com/cppalgorithm/random_sample_n.html">random_sample_n</a><br /><strong>sample N random elements from a range</strong> </p><p><a href="http://www.cppreference.com/cppalgorithm/random_shuffle.html">random_shuffle</a><br /><strong>randomly re-order elements in some range</strong><br />对范围内的元素随机调整次序。重载版本输入一个随机数产生操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/remove.html">remove</a><br /><strong>remove elements equal to certain value</strong><br />删除在范围内的所有等于指定的元素，注意，该函数并不真正删除元素。内置数组不适合使用 remove 和 remove_if 函数。 </p><p><a href="http://www.cppreference.com/cppalgorithm/remove_copy.html">remove_copy</a><br /><strong>copy a range of elements omitting those that match a certian value</strong><br />将所有不匹配的元素都复制到一个指定容器，返回的 OutputIterator 指向被拷贝的末元素的下一个位置。 </p><p><a href="http://www.cppreference.com/cppalgorithm/remove_copy_if.html">remove_copy_if</a><br /><strong>create a copy of a range of elements, omitting any for which a predicate is true</strong><br />将所有不匹配的元素拷贝到一个指定容器。 </p><p><a href="http://www.cppreference.com/cppalgorithm/remove_if.html">remove_if</a><br /><strong>remove all elements for which a predicate is true</strong><br />删除所有范围内输入操作结果为 true 的元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/replace.html">replace</a><br /><strong>replace every occurrence of some value in a range with another value</strong><br />将范围内的所有等于 old_value 的元素都用 new_value 替代。 </p><p><a href="http://www.cppreference.com/cppalgorithm/replace_copy.html">replace_copy</a><br /><strong>copy a range, replacing certain elements with new ones</strong><br />与 replace 类似，不过将结果写入另外一个容器。 </p><p><a href="http://www.cppreference.com/cppalgorithm/replace_copy_if.html">replace_copy_if</a><br /><strong>copy a range of elements, replacing those for which a predicate is true</strong><br />类似与 replace_if ，不过将结果写入另外一个容器 </p><p><a href="http://www.cppreference.com/cppalgorithm/replace_if.html">replace_if</a><br /><strong>change the values of elements for which a predicate is true</strong><br />将范围内的所有操作结果为 true 的元素用新值替代。 </p><p><a href="http://www.cppreference.com/cppalgorithm/reverse.html">reverse</a><br /><strong>reverse elements in some range</strong><br />将范围内元素重新按反序排列。 </p><p><a href="http://www.cppreference.com/cppalgorithm/reverse_copy.html">reverse_copy</a><br /><strong>create a copy of a range that is reversed</strong><br />类似与 reverse ，不过将结果写入另外一个容器。 </p><p><a href="http://www.cppreference.com/cppalgorithm/rotate.html">rotate</a><br /><strong>move the elements in some range to the left by some amount</strong><br />将范围内的元素移到容器末尾，由 middle 指向的元素成为容器第一个元素。 </p><p><a href="http://www.cppreference.com/cppalgorithm/rotate_copy.html">rotate_copy</a><br /><strong>copy and rotate a range of elements</strong><br />类似与 rotate ，不过将结果写入另外一个容器 </p><p><a href="http://www.cppreference.com/cppalgorithm/search.html">search</a><br /><strong>search for a range of elements</strong><br />给出了两个范围，返回一个 iterator ，指向在范围内第一次出现子序列的位置。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/search_n.html">search_n</a><br /><strong>search for N consecutive copies of an element in some range</strong><br />在范围内查找 value 出现 n 次的子序列。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/set_difference.html">set_difference</a><br /><strong>computes the difference between two sets</strong><br />构造一个排过序的序列，其中的元素出现在第一个序列中，但是不包含在第二个序列中。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/set_intersection.html">set_intersection</a><br /><strong>computes the intersection of two sets</strong><br />构造一个排过序的序列，其中的元素在两个序列中都存在。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/set_symmetric_difference.html">set_symmetric_difference</a><br /><strong>computes the symmetric difference between two sets</strong><br />构造一个排过序的序列，其中的元素在第一个序列中出现，但是不出现在第二个序列中。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/set_union.html">set_union</a><br /><strong>computes the union of two sets</strong><br />构造一个排过序的序列，它包含两个序列中的所有的不重复元素。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/sort.html">sort</a><br /><strong>sort a range into ascending order</strong><br />以升序重新排列范围内的元素，重载版本使用了自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/sort_heap.html">sort_heap</a><br /><strong>turns a heap into a sorted range of elements</strong><br />对范围内的序列重新排序，它假设该序列是个有序的堆。重载版本使用自定义的比较操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/stable_partition.html">stable_partition</a><br /><strong>divide elements into two groups while preserving their relative order</strong><br />与 partition 类似，不过它保证保留容器中的相对顺序。 </p><p><a href="http://www.cppreference.com/cppalgorithm/stable_sort.html">stable_sort</a><br /><strong>sort a range of elements while preserving order between equal elements</strong><br />类似与 sort ，不过保留相等元素之间的顺序关系。 </p><p><a href="http://www.cppreference.com/cppalgorithm/swap.html">swap</a><br /><strong>swap the values of two objects</strong><br />交换存储在两个对象中的值。 </p><p><a href="http://www.cppreference.com/cppalgorithm/swap_ranges.html">swap_ranges</a><br /><strong>swaps two ranges of elements</strong><br />将在范围内的元素与另外一个序列的元素值进行交换。 </p><p><a href="http://www.cppreference.com/cppalgorithm/transform.html">transform</a><br /><strong>applies a function to a range of elements</strong><br />将输入的操作作用在范围内的每个元素上，并产生一个新的序列。重载版本将操作作用在一对元素上，另外一个元素来自输入的另外一个序列。结果输出到指定的容器。 </p><p><a href="http://www.cppreference.com/cppalgorithm/unique.html">unique</a><br /><strong>remove consecutive duplicate elements in a range</strong><br />清除序列中重复的元素，和 remove 类似，它也不能真正的删除元素。重载版本使用了自定义的操作。 </p><p><a href="http://www.cppreference.com/cppalgorithm/unique_copy.html">unique_copy</a><br /><strong>create a copy of some range of elements that contains no consecutive duplicates</strong><br />类似与 unique ，不过它把结果输出到另外一个容器。 </p><p><a href="http://www.cppreference.com/cppalgorithm/upper_bound.html">upper_bound</a><br /><strong>searches for the last possible location to insert an element into an ordered range</strong><br />返回一个 iterator ，它指向在范围内的有序序列中插入 value 而不破坏容器顺序的最后一个位置，该位置标志了一个大于 value 的值。重载版本使用了输入的比较操作。</p><img src ="http://www.cppblog.com/FongLuo/aggbug/61373.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/FongLuo/" target="_blank">FongLuo</a> 2008-09-09 13:31 <a href="http://www.cppblog.com/FongLuo/archive/2008/09/09/61373.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>