Home | History | Annotate | Download | only in pop.heap
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <algorithm>
     11 
     12 // template<RandomAccessIterator Iter>
     13 //   requires ShuffleIterator<Iter> && LessThanComparable<Iter::value_type>
     14 //   void
     15 //   pop_heap(Iter first, Iter last);
     16 
     17 #include <algorithm>
     18 #include <random>
     19 #include <cassert>
     20 
     21 std::mt19937 randomness;
     22 
     23 void test(int N)
     24 {
     25     int* ia = new int [N];
     26     for (int i = 0; i < N; ++i)
     27         ia[i] = i;
     28     std::shuffle(ia, ia+N, randomness);
     29     std::make_heap(ia, ia+N);
     30     for (int i = N; i > 0; --i)
     31     {
     32         std::pop_heap(ia, ia+i);
     33         assert(std::is_heap(ia, ia+i-1));
     34     }
     35     std::pop_heap(ia, ia);
     36     delete [] ia;
     37 }
     38 
     39 int main()
     40 {
     41     test(1000);
     42 }
     43