28 lines
861 B
Java
28 lines
861 B
Java
package com.hithomelabs.princeton1.module8;
|
|
|
|
import com.hithomelabs.princeton1.module5.AbstractCustomSorts;
|
|
|
|
|
|
public class HeapSort<E> extends AbstractCustomSorts<E> {
|
|
|
|
@Override
|
|
public void sort(E[] arr) {
|
|
int N = arr.length;
|
|
|
|
E[] heapArr = (E[]) new Object[N+1];
|
|
// * * to simplify we copy original array and write it to the new array starting index 1
|
|
System.arraycopy(arr, 0, heapArr, 1, N);
|
|
// * * An array of size N holds a heap of size N-1
|
|
coreSortingLogic(heapArr, N);
|
|
// * * Re-copying the sorted array to the original
|
|
System.arraycopy(heapArr, 1, arr, 0, N);
|
|
}
|
|
|
|
/*
|
|
* * Implement the core sorting logic
|
|
* * P.S the provision of making the index 0 null for ease of use has already been done above
|
|
*/
|
|
private void coreSortingLogic(E[] arr, int N) {
|
|
}
|
|
}
|