9.1) Algorithms
- The C++ algorithms library provides a large number of functions to manipulate containers, arrays and strings in useful ways
- These functions typically use a pair of iterators to operate on a range of elements - the first pointing to the start of that range, the second pointing just beyond its end
- To operate on an entire container, we simply specify the range using the iterators returned by that container's
begin
andend
methods - Most algorithms are made available via
#include <algorithm>
; a small number require#include <numeric>
- Various forms of manipulation are supported, including:
- Sorting and searching (e.g.,
sort
,find
) - In-place transformations (e.g.,
reverse
,replace
) - Set operations (e.g.,
merge
) - Numerical operations (e.g.,
accumulate
,inner_product
)