(int arr[])
| 1 | public class HeapSort { |
| 2 | public void sort(int arr[]) { |
| 3 | int n = arr.length; |
| 4 | |
| 5 | // Build heap (rearrange array) |
| 6 | for (int i = n / 2 - 1; i >= 0; i--) |
| 7 | heapify(arr, n, i); |
| 8 | |
| 9 | // One by one extract an element from heap |
| 10 | for (int i = n - 1; i > 0; i--) { |
| 11 | // Move current root to end |
| 12 | int temp = arr[0]; |
| 13 | arr[0] = arr[i]; |
| 14 | arr[i] = temp; |
| 15 | |
| 16 | // call max heapify on the reduced heap |
| 17 | heapify(arr, i, 0); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | // To heapify a subtree rooted with node i which is |
| 22 | // an index in arr[]. n is size of heap |
no test coverage detected