int m = (start + end) / 2, i = start, j = m + 1, cursor = 0;
sort(data, start, m);
sort(data, m + 1, end);
int[] tmp = new int[end - start + 1];
while (i <= m && j <= end) tmp[cursor++] = (data[i] <= data[j]) ? data[i++] : data[j++];
while (i <= m) tmp[cursor++] = data[i++];
while (j <= end) tmp[cursor++] = data[j++];
System.arraycopy(tmp, 0, data, start, tmp.length);
网友评论