Answer the question
In order to leave comments, you need to log in
How does this merge algorithm (mergeSort) work?
public static void mergeSort(int[] array, int low, int high) {
if (high - low < 2) {
return;
}
int mid = (low + high) >>> 1;
mergeSort(array, low, mid);
mergeSort(array, mid, high);
int[] b = Arrays.copyOfRange(array, low, mid);
for (int i = low, j = mid, k = 0; k < b.length; i++) {
if (j == high || b[k] <= array[j]) {
array[i] = b[k++];
} else {
array[i] = array[j++];
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question