public static void main(String[] args) { int[] array = {6, 5, 3, 1, 8, 7, 2, 4}; MyUtils.printArray(array); sort(array); MyUtils.printArray(array); }
private static void buildHeap(int i, int e, int[] array) { int p = i; int l = 2 * p + 1; int r = 2 * p + 2; if (l < e && array[i] < array[l]) p = l; if (r < e && array[p] < array[r]) p = r; if (p != i) { swap(array, i, p); buildHeap(p, e, array); } MyUtils.printArray(array); }
public static void main(String[] args) { Integer[] array = {1, 3, 2, 2, 2, 3, 3, 3, 3, 3, 5, 7, 8}; Integer[] result = findNOccurrence(array, array.length / 3); MyUtils.printArray(result); }