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.12. Heapsort

Figure 16.12 demonstrates the Standard Library algorithms for performing the heapsort sorting algorithm, in which an array of elements is arranged into a data structure called a heap. For more information on Heapsort and for additional resources, see:

 1   // Fig. 16.12: fig16_12.cpp 2   // Algorithms push_heap, pop_heap, make_heap and sort_heap. 3   #include <iostream> 4   #include <algorithm> 5   #include <array> 6   #include <vector> 7   #include <iterator> 8   using namespace std; 9 10   int main()11   {12      const size_t SIZE = 10;13      array< int, SIZE > init = { 3, 100, 52, 77, 22, 31, 1, 98, 13, 40 };14      array< int, SIZE > a( init ); // copy of init ...

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