voidmergeSort(int[] a) { mergeSort(a, 0, a.length-1); } voidmergeSort(int[] a, int start, int end) { if (start >= end) return; intmid= (start+end)/2, i = start, j = mid+1, len = end-start+1, temp[] = newint[len];
mergeSort(a, i, mid); mergeSort(a, j, end);
for (int k=0;k<len;k++) if (j>end || i<=mid && a[i]<a[j]) temp[k] = a[i++]; else temp[k] = a[j++];