16.3.6. Basic Searching and Sorting Algorithms

Figure 16.6 demonstrates some basic searching and sorting Standard Library algorithms, including find, find_if, sort, binary_search, all_of, any_of, none_of and find_if_not.

 1   // Fig. 16.6: fig16_06.cpp 2   // Standard Library search and sort algorithms. 3   #include <iostream> 4   #include <algorithm> // algorithm definitions 5   #include <array> // array class-template definition 6   #include <iterator> 7   using namespace std; 8  9   bool greater10( int value ); // predicate function prototype10 11   int main()12   {13      const size_t SIZE = 10;14      array< int, SIZE > a = { 10, 2, 17, 5, 16, 8, 13, 11, 20, 7 };15      ostream_iterator< int > output( cout, ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.