Algorithm头文件简介

来源:互联网 发布:js 计算时间间隔 毫秒 编辑:程序博客网 时间:2024/05/01 17:47

STL Algorithms

Standard Template Library: Algorithms

 

The header <algorithm> defines acollection of functions especially designed to be used on ranges ofelements.

 

A range is any sequence of objects that can be accessed throughiterators or pointers, such as an array or an instance of some ofthe STL containers . Notice though, that algorithms operate throughiterators directly on the values, not affecting in any way thestructure of any possible container (it never affects the size orstorage allocation of the container).

 


Functions in <algorithm>

Non-modifying sequence operations :

for_each  Apply function to range(template function)

find  Find value in range (functiontemplate)

find_if  Find element in range (functiontemplate) 

find_end  Find last subsequence in range(function template) find_end(s1.begin(),s1.end(),s2.begin(),s2.end());返回s1中s2最后一次出现的位置的地址。

find_first_of  Find element from set inrange (function template) 

adjacent_find  Find equal adjacentelements in range (function template) 

count  Count appearances of value inrange (function template) 

count_if  Return number of elements inrange satisfying condition (functiontemplate) 

mismatch  Return first position wheretwo ranges differ (function template) 

equal  Test whether the elements in tworanges are equal (function template) 

search  Find subsequence in range(function template) 

search_n  Find succession of equalvalues in range (function template) 

 

 

Modifying sequence operations :

copy  Copy range of elements (functiontemplate) copy(num,num+N,num2);num的拷到num2里。

copy_backward  Copy range of elementsbackwards (function template) 

swap  Exchange values of two objects(function template) 

swap_ranges  Exchange values of tworanges (function template) copy(num,num+N,num2);交换俩数组的内容。

iter_swap  Exchange values of objectspointed by two iterators (function template) 

transform  Apply function to range(function template) 

replace  Replace value in range(function template) 

replace_if  Replace values in range(function template) 

replace_copy  Copy range replacing value(function template) 

replace_copy_if  Copy range replacingvalue (function template) 

fill  Fill range with value (functiontemplate) fill(num,num+N,x);用x填满数组。

fill_n  Fill sequence with value(function template) fill_n(num,n,x);用x填数组的前n个位置。

generate  Generate values for range withfunction (function template) 

generate_n  Generate values for sequencewith function (function template) 

remove  Remove value from range(function template) remove(num,num+N,x);从num中去掉x返回尾地址。

remove_if  Remove elements from range(function template) 

remove_copy  Copy range removing value(function template) 

remove_copy_i Copy range removingvalues (function template) 

unique  Remove consecutive duplicates inrange (function template) unique(num,num+N);相邻且相同的多个数中只留一个。

unique_copy  Copy range removingduplicates (function template) 

reverse  Reverse range (functiontemplate) 

reverse_copy  Copy range reversed(function template) 

rotate  Rotate elements in range(function template) rotate(num,num+x,num+N);旋转数组内容,使其以num[x]开头。

rotate_copy  Copy rotated range(function template) 

random_shuffle  Rearrange elements inrange randomly (function template) 

partition  Partition range in two(function template) 

stable_partition  Parition range in two- stable ordering (function template) 

 

 

Sorting :

sort  Sort elements in range (functiontemplate) 

stable_sort  Sort elements preservingorder of equivalents (function template) 

partial_sort  Partially Sort elements inrange (function template) 

partial_sort_copy  Copy and partiallysort range (function template) 

nth_element  Sort element in range(function template) 

 

 

Binary search (operating on sorted ranges):

lower_bound  Return iterator to lowerbound (function template) lower_bound(num,num+N,x)-num=num内小于x的个数

upper_bound  Return iterator to upperbound (function template) upper_bound(num,num+N,x)-num=num内小于等于x的个数

equal_range  Get subrange of equalelements (function template) 

binary_search  Test if value exists insorted array (function template) 

 

 

Merge (operating on sorted ranges):

merge  Merge sorted ranges (functiontemplate) 

inplace_merge  Merge consecutive sortedranges (function template) 

includes  Test whether sorted rangeincludes another sorted range (functiontemplate) 

set_union  Union of two sorted ranges(function template) 

set_intersection  Intersection of twosorted ranges (function template) 

set_difference  Difference of two sortedranges (function template) 

set_symmetric_difference  Symmetricdifference of two sorted ranges (functiontemplate) 

 

 

Heap :

push_heap  Push element into heap range(function template) 

pop_heap  Pop element from heap range(function template) 

make_heap  Make heap from range(function template) 

sort_heap  Sort elements of heap(function template) 

 

 

Min/max :

min  Return the lesser of two arguments(function template) 

max  Return the greater of two arguments(function template) 

min_element  Return smallest element inrange (function template) 

max_element  Return largest element inrange (function template) 

 

 

lexicographical_compare  Lexicographicalless-than comparison (function template) 若前者字典序比较靠前则返回1。

 

 

next_permutation  Transform range tonext permutation (function template) 变成下一个全排列,若没有则返回0。

prev_permutation  Transform range toprevious permutation (function template)

 

 

转自:http://blog.csdn.net/ly50247/archive/2009/07/07/4329518.aspx


挑了几个感觉可能有用的用了下。


原创粉丝点击