sort_heap
Sorts the heap (it is no longer a heap after the call)
You're viewing an older version of this page (#4184). View the current version.
Definition
The sort_heap() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class RandomAccessIterator >
void sort_heap(
RandomAccessIterator first,
RandomAccessIterator last
);
template < class RandomAccessIterator, class Predicate >
void sort_heap(
RandomAccessIterator first,
RandomAccessIterator last,
Predicate comp
);Parameters:
| Parameter | Description |
| first | A random-access iterator addressing the position of the first element in the target heap |
| last | A random-access iterator addressing the position one past the final element in the target heap |
| comp | User-defined predicate function object that defines sense in which one element is less than another. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
Description
Sort_heap function converts a heap into a sorted range (ascending order). It does the same thing than doing a http://codecogs.com/reference/computing/stl/algorithms/heap/pop_heap.php"pop_heap" on the heap until no more element is in the heap.
The first version compares objects using operator< and the second compares objects using a function object comp.
Return Value
None.
Complexity
Performs at most (last - first)*log(last - first) comparisons.
References
See Also
- http://www.codecogs.com/reference/computing/stl/algorithms/heap/make_heap.php"make_heap"
- http://http://www.codecogs.com/reference/computing/stl/algorithms/heap/is_heap.php"is_heap"
- http://www.codecogs.com/reference/computing/stl/algorithms/heap/push_heap.php"push_heap"
- http://www.codecogs.com/reference/computing/stl/algorithms/heap/sort_heap.php"sort_heap"