In the C++ Standard Library, algorithms are components that perform algorithmic operations on containers and other sequences.
Contents
The C++ standard provides some standard algorithms collected in the <algorithm>
standard header. A handful of algorithms are also in the <numeric>
header. All algorithms are in the std
namespace.
Categories of algorithms
The algorithms in the C++ Standard Library can be organized into the following categories.
find_if
, count
, search
)replace
, remove
, reverse
)sort
, stable_sort
, partial_sort
)lower_bound
, upper_bound
)make_heap
, push_heap
)min
, max
)Examples
OutputIterator copy(InputIterator source_begin, InputIterator source_end, OutputIterator destination_begin)
void fill(ForwardIterator destination_begin, ForwardIterator destination_end, T value)
InputIterator find(InputIterator begin, InputIterator end, T search_obje
(returns an iterator the found object or end
, if the object isn't found)const T& max(const T& a, const T& b)
returns the greater of the two argumentsForwardIterator max_element(ForwardIterator begin, ForwardIterator end)
finds the maximum element of a rangeconst T& min(const T& a, const T& b)
returns the smaller of the two argumentsForwardIterator min_element(ForwardIterator begin, ForwardIterator end)
finds the minimum element of a rangeReferences
Algorithm (C++) Wikipedia(Text) CC BY-SA