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

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.