STL - Algorithms


Tags:  cppstlalgorithms

References

Sorting

FunctionUse
sortSort elements
stable_sortSort elements preserving order of equivalents
partial_sortPartially sort elements in range
partial_sort_copyCopy and partially sort range
is_sortedCheck whether range is sorted
is_sorted_untilFind first unsorted element in range
nth_elementSort element in range

Binary search (on partitioned/sorted ranges)

FunctionUse
lower_boundReturn iterator to lower bound
upper_boundReturn iterator to upper bound
equal_rangeGet subrange of equal elements
binary_searchTest if value exists in sorted sequence

Merge (on sorted ranges)

FunctionUse
mergeMerge sorted ranges
inplace_mergeMerge consecutive sorted ranges
includesTest whether the sorted range includes another sorted range
set_unionUnion of two sorted ranges
set_intersectionIntersection of two sorted ranges
set_differenceDifference of two sorted ranges
set_symmetric_differenceSymmetric difference of two sorted ranges

Partition Operations

FunctionUse
is_partitionedTest whether range is partitioned
partitionPartition range in two
stable_partitionPartition range in two – stable ordering
partition_copyPartition range into two
partition_pointGet partition point

Heap Operations

FunctionUse
push_heapPush element into heap range
pop_heapPop element from heap range
make_heapMake heap from range
sort_heapSort elements of heap
is_heapTest if range is heap
is_heap_untilFind first element not in heap order
maxReturn the largest
minmaxReturn smallest and largest elements
min_elementReturn smallest element in range
max_elementReturn largest element in range
minmax_elementReturn smallest and largest elements in range

Other Operations

FunctionUse
lexicographical_compareLexicographical less-than comparison
next_permutationTransform range to next permutation
prev_permutationTransform range to previous permutation

Non-modifying sequence operations

FunctionUse
all_ofTest condition on all elements in range
any_ofTest if any element in range fulfills condition
none_ofTest if no elements fulfill condition
for_eachApply function to range
findFind value in range
find_ifFind element in range
find_if_notFind element in range (negative condition)
find_endFind last subsequence in range
find_first_ofFind element from set in range
adjacent_findFind equal adjacent elements in range
countCount appearances of value in range
count_ifReturn number of elements in range satisfying condition
mismatchReturn first position where two ranges differ
equalTest whether the elements in two ranges are equal
is_permutationTest whether range is permutation of another
searchSearch range for subsequence
search_nSearch range for element

Modifying sequence operations

FunctionUse
copyCopy range of elements
copy_nCopy elements
copy_ifCopy certain elements of range
copy_backwardCopy range of elements backward
moveMove range of elements
move_backwardMove range of elements backward
swapExchange values of two objects
swap_rangesExchange values of two ranges
iter_swapExchange values of objects pointed to by two iterators
transformTransform range
replaceReplace value in range
replace_ifReplace values in range
replace_copyCopy range replacing value
replace_copy_ifCopy range replacing value
fillFill range with value
fill_nFill sequence with value
generateGenerate values for range with function
generate_nGenerate values for sequence with function
removeRemove value from range
remove_ifRemove elements from range
remove_copyCopy range removing value
remove_copy_ifCopy range removing values
uniqueRemove consecutive duplicates in range
unique_copyCopy range removing duplicates
reverseReverse range
reverse_copyCopy range reversed
rotateRotate left the elements in range
rotate_copyCopy range rotated left
random_shuffleRandomly rearrange elements in range
shuffleRandomly rearrange elements in range using generator