1217 |
|
Arrays.sort(array, lo, hi); |
1218 |
|
} |
1219 |
|
static void merge(long[] array, int lo, int mid, int hi) { |
1220 |
< |
int n = hi - lo; |
1221 |
< |
long[] buf = new long[n]; |
1222 |
< |
int a = lo, b = mid; |
1223 |
< |
for (int i = 0; i < n; i++) |
1224 |
< |
buf[i] = (b == hi || (a < mid && array[a] < array[b])) ? |
1225 |
< |
array[a++] : array[b++]; |
1226 |
< |
System.arraycopy(buf, 0, array, lo, n); |
1220 |
> |
long[] buf = Arrays.copyOfRange(array, lo, mid); |
1221 |
> |
for (int i = 0, j = lo, k = mid; i < buf.length; j++) |
1222 |
> |
array[j] = (k == hi || buf[i] < array[k]) ? |
1223 |
> |
buf[i++] : array[k++]; |
1224 |
|
} |
1225 |
|
} |
1226 |
|
|
1229 |
|
*/ |
1230 |
|
public void testSortTaskDemo() { |
1231 |
|
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
1232 |
< |
long[] array = new long[1000]; |
1232 |
> |
long[] array = new long[1007]; |
1233 |
|
for (int i = 0; i < array.length; i++) |
1234 |
|
array[i] = rnd.nextLong(); |
1235 |
|
long[] arrayClone = array.clone(); |