Algorithm (C++)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

In the C++ Standard Library, algorithms are components that perform algorithmic operations on containers and other sequences.[1]

The C++ standard provides some standard algorithms collected in the <algorithm> standard header.[2] A handful of algorithms are also in the <numeric> header. All algorithms are in the std namespace.

Categories of algorithms[edit]

The algorithms in the C++ Standard Library can be organized into the following categories.

  • Non-modifying sequence operations (e.g. find_if, count, search)
  • Modifying sequence operations (e.g. replace, remove, reverse)
  • Sorting (e.g. sort, stable_sort, partial_sort)
  • Binary search (e.g. lower_bound, upper_bound)
  • Heap (e.g. make_heap, push_heap)
  • Min/max (e.g. min, max)


  • 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 arguments
  • ForwardIterator max_element(ForwardIterator begin, ForwardIterator end) finds the maximum element of a range
  • const T& min(const T& a, const T& b) returns the smaller of the two arguments
  • ForwardIterator min_element(ForwardIterator begin, ForwardIterator end) finds the minimum element of a range


  1. ^ ISO/IEC (2003). ISO/IEC 14882:2003(E): Programming Languages - C++ §25 Algorithms library [lib.algorithms] para. 1
  2. ^ Stroustrup, Bjarne (2009). Programming : principles and practice using C++. Upper Saddle River, NJ: Addison-Wesley. p. 729. ISBN 9780321543721. Retrieved 22 March 2012. The standard library algorithms are found in <algorithm>.

External links[edit]