O'Reilly logo

C++11 for Programmers, Second Edition by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16.3.11. lower_bound, upper_bound and equal_range

Figure 16.11 demonstrates algorithms lower_bound, upper_bound and equal_range.

 1   // Fig. 16.11: fig16_11.cpp 2   // Algorithms lower_bound, upper_bound and 3   // equal_range for a sorted sequence of values. 4   #include <iostream> 5   #include <algorithm> // algorithm definitions 6   #include <array> // aray class-template definition 7   #include <iterator> // ostream_iterator 8   using namespace std; 9 10   int main()11   {12      const size_t SIZE = 10;13      array< int, SIZE > a = { 2, 2, 4, 4, 4, 6, 6, 6, 6, 8 };14      ostream_iterator< int > output( cout, " " );15 16      cout << "array a contains:\n";17      copy( a.cbegin(), a.cend(), output );18 19 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required