sort_heap


Sort a heap.

Starting with a heap as an input sequence, produce a sorted collection. The first version uses operator< to compare elements, whereas the second version uses the binary function compare . Note that a heap ceases to be a heap when it is sorted.

Library

Standards<ToolKit>

Declaration


#include <algorithm>

template< class RandomAccessIterator >
void sort_heap
  (
  RandomAccessIterator first,
  RandomAccessIterator last
  );

template< class RandomAccessIterator, class Compare >
void sort_heap
  (
  RandomAccessIterator first,
  RandomAccessIterator last,
  Compare compare
  );
  

Complexity

Time complexity is N * log(N). Space complexity is constant.

Example

See push_heap .


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.