@Test public void sortInteger() { Integer[] sortIntegerArray = {9,2,3,4}; MergeSort.sort(sortIntegerArray); Integer[] resultArray = {2,3,4,9}; Assert.assertArrayEquals(sortIntegerArray, resultArray); }
private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi) { if (hi <= lo) return; int mid = lo + (hi - lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid + 1, hi); merge(a, aux, lo, mid, hi); }
MergeSort { private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi) { if (hi <= lo) return; int mid = lo + (hi - lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid + 1, hi); merge(a, aux, lo, mid, hi); } }
MergeSort { private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi) { if (hi <= lo) return; int mid = lo + (hi - lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid + 1, hi); merge(a, aux, lo, mid, hi); } private  MergeSort(); }
MergeSort { private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi) { if (hi <= lo) return; int mid = lo + (hi - lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid + 1, hi); merge(a, aux, lo, mid, hi); } private  MergeSort(); static void sort(Comparable[] a); static int[] indexSort(Comparable[] a); static void main(String[] args); }
MergeSort { private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi) { if (hi <= lo) return; int mid = lo + (hi - lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid + 1, hi); merge(a, aux, lo, mid, hi); } private  MergeSort(); static void sort(Comparable[] a); static int[] indexSort(Comparable[] a); static void main(String[] args);  }