publicstaticvoidmergeSort(int[] a, int lo, int hi){ if (hi<=lo) return; int mi = (lo + hi) / 2; mergeSort(a, lo, mi); mergeSort(a, mi+1, hi); merge(a, lo, mi, hi); } publicstaticvoidmerge(int[] a, int lo, int mi, int hi){ int c[] = newint[hi - lo + 1]; int m = 0; for (int i = lo, j = mi+1;!(i > mi && j > hi);) { if (i > mi) { c[m++] = a[j++]; } elseif (j > hi) { c[m++] = a[i++]; } elseif (a[i] >= a[j]) { c[m++] = a[j++]; } else { c[m++] = a[i++]; } } for (int i = 0, j = lo; i < c.length;) { a[j++] = c[i++]; } }