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 // sort_heap(Iter first, Iter last); 16 17 #include <algorithm> 18 #include <cassert> 19 20 void test(unsigned N) 21 { 22 int* ia = new int [N]; 23 for (int i = 0; i < N; ++i) 24 ia[i] = i; 25 std::random_shuffle(ia, ia+N); 26 std::make_heap(ia, ia+N); 27 std::sort_heap(ia, ia+N); 28 assert(std::is_sorted(ia, ia+N)); 29 delete [] ia; 30 } 31 32 int main() 33 { 34 test(0); 35 test(1); 36 test(2); 37 test(3); 38 test(10); 39 test(1000); 40 } 41