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.8. copy_backward, merge, unique and reverse

Figure 16.8 demonstrates algorithms copy_backward, merge, unique and reverse.

 1   // Fig. 16.8: fig16_08.cpp 2   // Algorithms copy_backward, merge, unique and reverse. 3   #include <iostream> 4   #include <algorithm> // algorithm definitions 5   #include <array> // array class-template definition 6   #include <iterator> // ostream_iterator 7   using namespace std; 8  9   int main()10   {11      const size_t SIZE = 5;12      array< int, SIZE > a1 = { 1, 3, 5, 7, 9 };13      array< int, SIZE > a2 = { 2, 4, 5, 7, 9 };14      ostream_iterator< int > output( cout, " " );15 16      cout << "array a1 contains: ";17      copy( a1.cbegin(), a1.cend(), output ); // display ...

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