我知道我应该处理一些输入。但是代码会是什么样子?认为
public static void mergeSort(Comparable[] a, int left, int right) {
if (right <= left) return;
int mid = left + (right – left) / 2;
mergeSort(a, left, mid);
mergeSort(a, mid + 1, right);
merge(a, left, mid, right);
}
public void merge(Comparable[] a, int left, int mid,int right) {
for (int k = left; k <= right; k++) aux[k] = a[k];
int i = left; j = mid + 1;
for (int k = left; k <= right; k++) {
if (i > mid) a[k] = aux[j++];
else if (j > right) a[k] = aux[i++];
else if (less(aux[j], aux[i]) a[k] = aux[j++];
else a[k] = aux[i++];
}
}
是归并排序方法。