MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / sort

Method sort

Programs/HeapSort.java:2–19  ·  view source on GitHub ↗
(int arr[])

Source from the content-addressed store, hash-verified

1public 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

Callers 5

mainMethod · 0.95
bucketSortMethod · 0.45
mainMethod · 0.45
KruskalAlgoMethod · 0.45
mainMethod · 0.45

Calls 1

heapifyMethod · 0.95

Tested by

no test coverage detected