Description
Sorts the array in ascending order using heap sort. Equivalent to Algo::HeapSort with TLess<>. A predicate overload is available for custom ordering. After the call the array is sorted but is no longer a valid heap.
Caveats & Gotchas
- • HeapSort is not stable — equal elements may appear in any relative order after sorting. Use Sort() or StableSortBy() if stability matters.
- • After HeapSort the array is sorted, not heapified. If you subsequently call HeapPush or HeapPop you must call Heapify() first to rebuild the heap structure.
- • Raw pointer arrays are automatically dereferenced by the predicate wrapper, matching the behavior of other heap operations on pointer arrays.
Signature
void HeapSort() Return Type
void Example
Heap-sorting an integer array C++
TArray<int32> Values = {5, 2, 8, 1, 9, 3};
Values.HeapSort();
// Values is now {1, 2, 3, 5, 8, 9}
// Descending order:
Values.HeapSort(TGreater<int32>()); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?