C++ algorithm library
The C++ Standard Library’s <algorithm> header provides a comprehensive suite of functions designed to operate on sequences of elements, commonly referred to as ranges. These functions facilitate a wide array of operations, including searching, sorting, counting, and manipulating data.
Non-Modifying Sequence Operations
Function Description std::all_of Returns true if all elements in the range satisfy the given predicate. std::any_of Returns true if any element in the range satisfies the given predicate. std::none_of Returns true if no elements in the range satisfy the given predicate. std::for_each Applies a function to each element in the range. std::find Searches for the first occurrence of a specified value in the range. std::find_if Searches for the first element in the range that satisfies the given predicate. std::find_if_not Searches for the first element in the range that does not satisfy the given predicate. std::find_end Searches for the last occurrence of a subsequence in the range. std::find_first_of Searches for the first element in the range that matches any element from another range. std::adjacent_find Searches for the first occurrence of consecutive identical elements in the range. std::count Returns the number of elements in the range that are equal to a specified value. std::count_if Returns the number of elements in the range that satisfy the given predicate. std::mismatch Finds the first position where two ranges differ. std::equal Checks if two ranges are equal. std::is_permutation Checks if one range is a permutation of another. std::search Searches for the first occurrence of a subsequence within the range. std::search_n Searches for the first occurrence of n consecutive elements that are equal to a specified value.
Modifying Sequence Operations
Function Description std::copyCopies elements from one range to another. std::copy_nCopies a specified number of elements from one range to another. std::copy_ifCopies elements from a range that satisfy a given predicate. std::copy_backwardCopies elements from one range to another, starting from the end. std::moveMoves elements from one range to another. std::move_backwardMoves elements from one range to another, starting from the end. std::swapExchanges the values of two objects. std::swap_rangesExchanges the values of two ranges. std::iter_swapExchanges the values of the elements pointed to by two iterators. std::transformApplies a function to each element in a range and writes the result to another range. std::replaceReplaces all occurrences of a value in a range with another value. std::replace_ifReplaces elements in a range that satisfy a given predicate with another value. std::replace_copyCopies a range, replacing all occurrences of a value in the new range. std::replace_copy_ifCopies a range, replacing elements that satisfy a given predicate in the new range. std::fillFills a range with a specified value. std::fill_nFills a specified number of elements in a range with a value. std::generateGenerates values for a range using a function. std::generate_nGenerates values for a specified number of elements in a range using a function. std::removeRemoves elements with a specific value from a range (logically, without changing the container size). std::remove_ifRemoves elements from a range that satisfy a given predicate. std::remove_copyCopies a range, excluding elements with a specific value. std::remove_copy_ifCopies a range, excluding elements that satisfy a given predicate. std::uniqueRemoves consecutive duplicate elements in a range. std::unique_copyCopies a range, removing consecutive duplicates in the new range. std::reverseReverses the elements in a range. std::reverse_copyCopies a range, reversing the elements in the new range. std::rotateRotates the elements in a range to the left. std::rotate_copyCopies a range, rotating the elements in the new range to the left. std::random_shuffleRandomly rearranges elements in a range. std::shuffleRandomly rearranges elements in a range using a specified random generator.
Partitions
Function Description std::is_partitionedTests whether the range is partitioned according to a specified predicate. std::partitionRearranges the elements in the range so that elements satisfying a predicate appear before those that do not. std::stable_partitionPartitions the range into two groups while preserving the relative order of elements in each group. std::partition_copyCopies elements from the input range into two separate ranges based on a predicate. std::partition_pointReturns an iterator to the partition point of a range that has already been partitioned.
Sorting
Function Description std::sort Sorts the elements in the range in ascending order. std::stable_sort Sorts the elements in the range while preserving the relative order of equivalent elements. std::partial_sort Sorts the first n elements in the range, leaving the rest unsorted. std::partial_sort_copy Copies and partially sorts the elements from the input range to another range. std::is_sorted Checks if the elements in the range are sorted. std::is_sorted_until Finds the first unsorted element in the range. std::nth_element Rearranges the elements in the range so that the nth element is in its sorted position.
Binary Search (Operating on Partitioned/Sorted Ranges)
Function Description std::lower_boundReturns an iterator to the first element that is not less than the specified value in a sorted range. std::upper_boundReturns an iterator to the first element that is greater than the specified value in a sorted range. std::equal_rangeReturns a pair of iterators defining the subrange of elements that are equal to a specified value. std::binary_search Tests if a specified value exists in a sorted sequence.
Merge (Operating on Sorted Ranges)
Heap Operations
Min/Max Operations
Function Description std::min Returns the smallest of two or more values. std::max Returns the largest of two or more values. std::minmax Returns the smallest and largest of two or more values as a pair. std::min_element Returns an iterator to the smallest element in a range. std::max_element Returns an iterator to the largest element in a range. std::minmax_element Returns iterators to the smallest and largest elements in a range as a pair.
Other Operations
Key Features of the algorithm Library
Non-Modifying Sequence Operations: Functions that analyze or search ranges without altering their elements.
Modifying Sequence Operations: Functions that modify the elements within a range.
Sorting and Related Operations: Functions that order elements within a range or perform operations related to sorting.
Set Operations: Functions that perform standard set operations on sorted ranges.
Heap Operations: Functions that manage heap structures within ranges.
Minimum and Maximum Operations: Functions that determine the smallest or largest elements in a range.
Warning : Undefined array key "HTTP_USER_AGENT" in
/bitnami/wordpress/wp-content/themes/twentynineteen/footer.php on line
85
Deprecated : strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in
/bitnami/wordpress/wp-content/themes/twentynineteen/footer.php on line
85