(int arr[])
| 42 | public class HeapSort |
| 43 | { |
| 44 | public void sort(int arr[]) |
| 45 | { |
| 46 | int n = arr.length; |
| 47 | |
| 48 | // Build heap (rearrange array) |
| 49 | for (int i = n / 2 - 1; i >= 0; i--) |
| 50 | heapify(arr, n, i); |
| 51 | |
| 52 | // One by one extract an element from heap |
| 53 | for (int i=n-1; i>0; i--) |
| 54 | { |
| 55 | // Move current root to end |
| 56 | int temp = arr[0]; |
| 57 | arr[0] = arr[i]; |
| 58 | arr[i] = temp; |
| 59 | |
| 60 | // call max heapify on the reduced heap |
| 61 | heapify(arr, i, 0); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // To heapify a subtree rooted with node i which is |
| 66 | // an index in arr[]. n is size of heap |
no test coverage detected