# 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:

Function | Description |
---|---|

all_of | The following function tests a condition to all the elements of the range. |

any_of | The following function tests a condition to some or any of the elements of the range |

none_of | The following function checks if none of the elements follow the condition or not. |

for_each | The function applies an operation to all the elements of the range. |

find | The function finds a value in the range. |

find_if | The function finds for an element in the range. |

find_if_not | The function finds an element in the range but in the opposite way as the above one. |

find_end | The function is used to return the last element of the range. |

find_first_of | The function finds for the element that satisfies a condition and occurs at the first. |

adjacent_find | The function makes a search for finding the equal and adjacent elements in a range. |

count | The function returns the count of a value in the range. |

count_if | The function returns the count of values that satisfies a condition. |

mismatch | The function returns the value in sequence which is the first mismatch. |

equal | The function is used to check if the two ranges have all elements equal. |

is_permutation | The function checks whether the range in reference is a permutation of some other range. |

search | The function searches for the subsequence in a range. |

search_n | The function searches the range for the occurrence of an element. |

## Modifying sequence operations

Function | Description |
---|---|

copy | The function copies the range of elements. |

copy_n | The function copies n elements of the range |

copy_if | The function copies the elements of the range if a certain condition is fulfilled. |

copy_backward | The function copies the elements in a backward order |

move | The function moves the ranges of elements. |

move_backward | The function moves the range of elements in the backward order |

swap | The function swaps the value of two objects. |

swap_ranges | The function swaps the value of two ranges. |

iter_swap | The function swaps the values of two iterators under reference. |

transform | The function transforms all the values in a range. |

replace | The function replaces the values in the range with a specific value. |

replace_if | The function replaces the value of the range if a certain condition is fulfilled. |

replace_copy | The function copies the range of values by replacing with an element. |

replace_copy_if | The function copies the range of values by replacing with an element if a certain condition is fulfilled. |

fill | The function fills the values in the range with a value. |

fill_n | The function fills the values in the sequence. |

generate | The function is used for the generation of values of the range. |

generate_n | The function is used for the generation of values of the sequence. |

remove | The function removes the values from the range. |

remove_if | The function removes the values of the range if a condition is fulfilled. |

remove_copy | The function copies the values of the range by removing them. |

remove_copy_if | The function copies the values of the range by removing them if a condition is fulfilled. |

unique | The function identifies the unique element of the range. |

unique_copy | The function copies the unique elements of the range. |

reverse | The function reverses the range. |

reverse_copy | The function copies the range by reversing values. |

rotate | The function rotates the elements of the range in left direction. |

rotate_copy | The function copies the elements of the range which is rotated left. |

random_shuffle | The function shuffles the range randomly. |

shuffle | The function shuffles the range randomly with the help of a generator. |

## Partitions

Function | Description |
---|---|

is_partitioned | The function is used to deduce whether the range is partitioned or not. |

partition | The function is used to partition the range. |

stable_partition | The function partitions the range in two stable halves. |

partition_copy | The function copies the range after partition. |

partition_point | The function returns the partition point for a range. |

## Sorting

Function | Description |
---|---|

sort | The function sorts all the elements in a range. |

stable_sort | The function sorts the elements in the range maintaining the relative equivalent order. |

partial_sort | The function partially sorts the elements of the range. |

partial_sort_copy | The function copies the elements of the range after sorting it. |

is_sorted | The function checks whether the range is sorted or not. |

is_sorted_until | The function checks till which element a range is sorted. |

nth_element | The functions sorts the elements in the range. |

## Binary search

Function | Description |
---|---|

lower_bound | Returns the lower bound element of the range. |

upper_bound | Returns the upper bound element of the range. |

equal_range | The function returns the subrange for the equal elements. |

binary_search | The function tests if the values in the range exists in a sorted sequence or not. |

## Merge

Function | Description |
---|---|

merge | The function merges two ranges that are in a sorted order. |

inplace_merge | The function merges two consecutive ranges that are sorted. |

includes | The function searches whether the sorted range includes another range or not. |

set_union | The function returns the union of two ranges that is sorted. |

set_intersection | The function returns the intersection of two ranges that is sorted. |

set_difference | The function returns the difference of two ranges that is sorted. |

set_symmetric_difference | The function returns the symmetric difference of two ranges that is sorted. |

## Heap

Function | Description |
---|---|

push_heap | The function pushes new elements in the heap. |

pop_heap | The function pops new elements in the heap. |

make_heap | The function is used for the creation of a heap. |

sort_heap | The function sorts the heap. |

is_heap | The function checks whether the range is a heap. |

is_heap_until | The function checks till which position a range is a heap. |

## Min/Max

Function | Description |
---|---|

min | Returns the smallest element of the range. |