HEap Sort
Fri Nov 29 2024 07:05:10 GMT+0000 (Coordinated Universal Time)
Saved by
@pcube312
void heapSort(vector<int>& arr){
int n = arr.size();
// Build heap (rearrange vector)
for (int i = n / 2 - 1; i >= 0; i--)
heapify(arr, n, i);
// One by one extract an element from heap
for (int i = n - 1; i > 0; i--) {
// Move current root to end
swap(arr[0], arr[i]);
// Call max heapify on the reduced heap
heapify(arr, i, 0);
}
}
content_copyCOPY
Comments