Algorithm (C )
   HOME

TheInfoList



OR:

In the C++
Standard Library In computer programming, a standard library is the library (computing), library made available across Programming language implementation, implementations of a programming language. Often, a standard library is specified by its associated program ...
, the algorithms library provides various functions that perform
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
ic operations on
containers A container is any receptacle or enclosure for holding a product used in storage, packaging, and transportation, including shipping. Things kept inside of a container are protected on several sides by being inside of its structure. The term ...
and other sequences, represented by
Iterator In computer programming, an iterator is an object that progressively provides access to each item of a collection, in order. A collection may provide multiple iterators via its interface that provide items in different orders, such as forwards ...
s.
ISO The International Organization for Standardization (ISO ; ; ) is an independent, non-governmental, international standard development organization composed of representatives from the national standards organizations of member countries. Me ...
/ IEC (2003). '' ISO/IEC 14882:2003(E): Programming Languages - C++ ยง25 Algorithms library ib.algorithms' para. 1
The C++ standard provides some standard algorithms collected in the standard header. A handful of algorithms are also in the header. All algorithms are in the
namespace In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
.


Execution policies

C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
provides the ability for many algorithms to optionally take an execution policy, which may allow implementations to execute the algorithm in parallel (i.e. by using threads or
SIMD Single instruction, multiple data (SIMD) is a type of parallel computer, parallel processing in Flynn's taxonomy. SIMD describes computers with multiple processing elements that perform the same operation on multiple data points simultaneousl ...
instructions). There are four different policy types, each indicating different semantics about the order in which element accesses are allowed to be observed relative to each other * , which indicates that the execution of the algorithm must happen on the thread which invokes the function, and the order of element accesses should execute in sequence. It is equivalent to calling the function without an execution policy * , which indicates that the execution of the algorithm may happen across multiple threads, however within each thread the order of element accesses are made in sequence (i.e. element accesses may not be done concurrently) * , which indicates that the execution of the algorithm may happen across multiple threads, and element accesses do not have to be performed in order within the same thread * , which indicates that the execution of the algorithm must happen on the thread which invokes the function, however the order of element accesses may be performed out of sequence It is up to the user to ensure that the operations performed by the function are
thread safe In multi-threaded computer programming, a function is thread-safe when it can be invoked or accessed concurrently by multiple threads without causing unexpected behavior, race conditions, or data corruption. As in the multi-threaded context where ...
when using policies which may execute across different threads.


Ranges

C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
adds versions of the algorithms defined in the header which operate on ranges rather than pairs of iterators. The ranges versions of algorithm functions are scoped within the namespace. They extend the functionality of the basic algorithms by allowing iterator-sentinel pairs to be used instead of requiring that both iterators be of the same type and also allowing interoperability with the objects provided by the ranges header without requiring the user to manually extract the iterators.


Non-modifying sequence operations


Predicate checking algorithms

Checks if a given predicate evaluates to true for some amount of objects in the range, or returns the amount of objects that do * * * * * *


Comparison algorithms

Compares two ranges for some property * * * * * * *


Searching algorithms

Finds the first or last position in a range where the subsequent elements satisfy some predicate * * * * * * * * * * * *


Binary search algorithms

Provides
Binary search In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the m ...
operations on ranges. It is undefined behaviour to use these on ranges which are not sorted. * * * *


Maximum/Minimum search algorithms

Finds the maximum or minimum element in a range, as defined by some comparison predicate * * *


Property checking algorithms

Checks if an entire range satisfies some property * * *


Modifying sequence operations


Copying algorithms

Transfers the elements from one range into another * * * * * * * * *


Partitioning algorithms

Moves the elements of a range in-place so the range is partitioned with respect to some property * * * * * *


Sorting algorithms

Sorts or partially sorts a range in-place * * * *


Populating algorithms

Populates a given range without reading the values contained within * * *


Transforming algorithms

Transforms each element of a given range in-place * * * * *


Reordering algorithms

Changes the order of elements within a range in-place * * * * *


Heap algorithms

Provides algorithms to create, insert, and remove elements from a max heap * * * *


References

{{reflist


External links


C++ reference for standard algorithms
C++ Standard Library Articles with example C++ code