C++ Data StructuresLesson 56Free preview
C++ Algorithms
This lesson is part of C++ · All levels
Summary
Header <algorithm> contains a set of ready-to-use functions for processing data in containers, such as sort, find, count, reverse, and for_each. Most algorithms work with an iterator range from begin() to end(), so that one function can be used on a vector, list, or array. Using the STL algorithm, code becomes shorter, more testable, and easier to read than writing manual repetitions.
Key points
- All algorithms accept the iterator range from begin() to end().
- Sort, reverse, and remove change the contents of the container in place.
- Find and search don't change the data, they're returning the iterator of the search results.
- To sum the elements, use accumulate from the header <numeric>.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.