Home Â» C++ Algorithm

# C++ Algorithm Functions

The library defines a large number of functions that are specially suited to be used on a large number of elements at a time or say a range. Now let’s straightway take a look at these functions.

## Non-modifying sequence operations:

FunctionDescription
all_ofThe following function tests a condition to all the elements of the range.
any_ofThe following function tests a condition to some or any of the elements of the range
none_ofThe following function checks if none of the elements follow the condition or not.
for_eachThe function applies an operation to all the elements of the range.
findThe function finds a value in the range.
find_ifThe function finds for an element in the range.
find_if_notThe function finds an element in the range but in the opposite way as the above one.
find_endThe function is used to return the last element of the range.
find_first_ofThe function finds for the element that satisfies a condition and occurs at the first.
adjacent_findThe function makes a search for finding the equal and adjacent elements in a range.
countThe function returns the count of a value in the range.
count_ifThe function returns the count of values that satisfies a condition.
mismatchThe function returns the value in sequence which is the first mismatch.
equalThe function is used to check if the two ranges have all elements equal.
is_permutationThe function checks whether the range in reference is a permutation of some other range.
searchThe function searches for the subsequence in a range.
search_nThe function searches the range for the occurrence of an element.

## Modifying sequence operations

FunctionDescription
copyThe function copies the range of elements.
copy_nThe function copies n elements of the range
copy_ifThe function copies the elements of the range if a certain condition is fulfilled.
copy_backwardThe function copies the elements in a backward order
moveThe function moves the ranges of elements.
move_backwardThe function moves the range of elements in the backward order
swapThe function swaps the value of two objects.
swap_rangesThe function swaps the value of two ranges.
iter_swapThe function swaps the values of two iterators under reference.
transformThe function transforms all the values in a range.
replaceThe function replaces the values in the range with a specific value.
replace_ifThe function replaces the value of the range if a certain condition is fulfilled.
replace_copyThe function copies the range of values by replacing with an element.
replace_copy_ifThe function copies the range of values by replacing with an element if a certain condition is fulfilled.
fillThe function fills the values in the range with a value.
fill_nThe function fills the values in the sequence.
generateThe function is used for the generation of values of the range.
generate_nThe function is used for the generation of values of the sequence.
removeThe function removes the values from the range.
remove_ifThe function removes the values of the range if a condition is fulfilled.
remove_copyThe function copies the values of the range by removing them.
remove_copy_ifThe function copies the values of the range by removing them if a condition is fulfilled.
uniqueThe function identifies the unique element of the range.
unique_copyThe function copies the unique elements of the range.
reverseThe function reverses the range.
reverse_copyThe function copies the range by reversing values.
rotateThe function rotates the elements of the range in left direction.
rotate_copyThe function copies the elements of the range which is rotated left.
random_shuffleThe function shuffles the range randomly.
shuffleThe function shuffles the range randomly with the help of a generator.

## Partitions

FunctionDescription
is_partitionedThe function is used to deduce whether the range is partitioned or not.
partitionThe function is used to partition the range.
stable_partitionThe function partitions the range in two stable halves.
partition_copyThe function copies the range after partition.
partition_pointThe function returns the partition point for a range.

## Sorting

FunctionDescription
sortThe function sorts all the elements in a range.
stable_sortThe function sorts the elements in the range maintaining the relative equivalent order.
partial_sortThe function partially sorts the elements of the range.
partial_sort_copyThe function copies the elements of the range after sorting it.
is_sortedThe function checks whether the range is sorted or not.
is_sorted_untilThe function checks till which element a range is sorted.
nth_elementThe functions sorts the elements in the range.

## Binary search

FunctionDescription
lower_boundReturns the lower bound element of the range.
upper_boundReturns the upper bound element of the range.
equal_rangeThe function returns the subrange for the equal elements.
binary_searchThe function tests if the values in the range exists in a sorted sequence or not.

## Merge

FunctionDescription
mergeThe function merges two ranges that are in a sorted order.
inplace_mergeThe function merges two consecutive ranges that are sorted.
includesThe function searches whether the sorted range includes another range or not.
set_unionThe function returns the union of two ranges that is sorted.
set_intersectionThe function returns the intersection of two ranges that is sorted.
set_differenceThe function returns the difference of two ranges that is sorted.
set_symmetric_differenceThe function returns the symmetric difference of two ranges that is sorted.

## Heap

FunctionDescription
push_heapThe function pushes new elements in the heap.
pop_heapThe function pops new elements in the heap.
make_heapThe function is used for the creation of a heap.
sort_heapThe function sorts the heap.
is_heapThe function checks whether the range is a heap.
is_heap_untilThe function checks till which position a range is a heap.

## Min/Max

FunctionDescription
minReturns the smallest element of the range.
maxReturns the largest element of the range.minmaxReturns the smallest and largest element of the range.min_elementReturns the smallest element of the range.max_elementReturns the largest element of the range.minmax_elementReturns the smallest and largest element of the range.