【STL】algorithm


algorithm

1.        algorithm是STL中的一种,主要是用来分类和排序的。be used on ranges of elements

2.        谓词:用来描述或判定客体性质、特征或者客体之间关系的词项。
例如:"猫是动物"一句中的"是动物"就是一个谓词,而"猫"是客体。"3 大于 2"中"大于"是一个谓词。

Functions in <algorithm>

Non-modifying sequence operations:

1.        all_of :Testcondition on all elements in range (functiontemplate )

 

any_of 

Test ifany element in range fulfills condition (function template )

none_of 

Test ifno elements fulfill condition (function template )

for_each

Applyfunction to range (function template )

find:利用等于操作符,对范围内的元素与输入值进行比较,匹配时,返回该元素的一个指针

Findvalue in range (function template )

find_if

Findelement in range (function template )

find_if_not 

Findelement in range (negative condition) (function template )

find_end

Find lastsubsequence in range (function template )

find_first_of

Findelement from set in range (function template )

adjacent_find

Findequal adjacent elements in range (function template )

count

Countappearances of value in range (function template )

count_if

Returnnumber of elements in range satisfying condition (function template )

mismatch

Returnfirst position where two ranges differ (function template )

equal

Testwhether the elements in two ranges are equal (function template )

is_permutation 

Testwhether range is permutation of another (function template )

search

Searchrange for subsequence (function template )

search_n

Searchrange for elements (function template )


Modifying sequence operations:

copy

Copyrange of elements (function template )

copy_n 

Copyelements (function template )

copy_if 

Copycertain elements of range (function template )

copy_backward

Copyrange of elements backward (function template )

move 

Move rangeof elements (function template )

move_backward 

Moverange of elements backward (function template )

swap

Exchangevalues of two objects (function template )

swap_ranges

Exchangevalues of two ranges (function template )

iter_swap

Exchangevalues of objects pointed by two iterators (function template )

transform

Transformrange (function template )

replace

Replacevalue in range (function template )

replace_if

Replacevalues in range (function template )

replace_copy

Copyrange replacing value (function template )

replace_copy_if

Copyrange replacing value (function template )

fill

Fillrange with value (function template )

fill_n

Fillsequence with value (function template )

generate

Generatevalues for range with function (function template )

generate_n

Generatevalues for sequence with function (function template )

remove

Removevalue from range (function template )

remove_if

Removeelements from range (function template )

remove_copy

Copyrange removing value (function template )

remove_copy_if

Copyrange removing values (function template )

unique

Removeconsecutive duplicates in range (function template )

unique_copy

Copyrange removing duplicates (function template )

reverse

Reverserange (function template )

reverse_copy

Copyrange reversed (function template )

rotate

Rotateleft the elements in range (function template )

rotate_copy

Copyrange rotated left (function template )

random_shuffle

Randomlyrearrange elements in range (function template )

shuffle 

Randomlyrearrange elements in range using generator (function template )


Partitions:

is_partitioned 

Testwhether range is partitioned (function template )

partition

Partitionrange in two (function template )

stable_partition

Partitionrange in two - stable ordering (function template )

partition_copy 

Partitionrange into two (function template )

partition_point 

Getpartition point (function template )


Sorting:

sort

Sortelements in range (function template )

stable_sort

Sortelements preserving order of equivalents (function template )

partial_sort

Partiallysort elements in range (function template )

partial_sort_copy

Copy andpartially sort range (function template )

is_sorted 

Checkwhether range is sorted (function template )

is_sorted_until 

Findfirst unsorted element in range (function template )

nth_element

Sortelement in range (function template )


Binary search (operating on partitioned/sorted ranges):

lower_bound

Returniterator to lower bound (function template )

upper_bound

Returniterator to upper bound (function template )

equal_range

Getsubrange of equal elements (function template )

binary_search

Test ifvalue exists in sorted sequence (function template )


Merge (operating on sorted ranges):

merge

Mergesorted ranges (function template )

inplace_merge

Mergeconsecutive sorted ranges (function template )

includes

Testwhether sorted range includes another sorted range (function template )

set_union

Union oftwo sorted ranges (function template )

set_intersection

Intersectionof two sorted ranges (function template )

set_difference

Differenceof two sorted ranges (function template )

set_symmetric_difference

Symmetricdifference of two sorted ranges (function template )


Heap:

push_heap

Pushelement into heap range (function template )

pop_heap

Popelement from heap range (function template )

make_heap

Make heapfrom range (function template )

sort_heap

Sortelements of heap (function template )

is_heap 

Test ifrange is heap (function template )

is_heap_until 

Findfirst element not in heap order (function template )


Min/max:

min

Returnthe smallest (function template )

max

Returnthe largest (function template )

minmax 

Returnsmallest and largest elements (function template )

min_element

Returnsmallest element in range (function template )

max_element

Returnlargest element in range (function template )

minmax_element 

Returnsmallest and largest elements in range (function template )


Other:

lexicographical_compare

Lexicographicalless-than comparison (function template )

next_permutation

Transformrange to next permutation (function template )

prev_permutation

Transformrange to previous permutation (function template )

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值