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); } }