Monday, September 11, 2017

C++11: Algorithms: is_heap

C++11 added an is_heap algorithm. Here is an example:

#include <algorithm>
#include <iostream>

int main()
{
  int myArray[7]  = { 100,
                   50,     40,
                 20, 30,  10, 5};

  int * inIterBegin   = &myArray[0];
  int * inIterEnd     = &myArray[8];

  bool arrayIsAHeap = std::is_heap(inIterBegin , inIterEnd);
  
  std::cout << arrayIsAHeap << " ";

  myArray[1] = 200;
  arrayIsAHeap = std::is_heap(inIterBegin , inIterEnd);

  std::cout << arrayIsAHeap << std::endl;
  return 0;
}
// Output: 1 0
Reference: https://isocpp.org/wiki/faq/cpp11-library-stl#cpp11-algorithms

No comments:

Post a Comment