Merge pull request #681 from guoxiaoxu/master

Update MergeSort.java
This commit is contained in:
Libin Yang
2019-01-13 16:42:52 +08:00
committed by GitHub

View File

@ -70,26 +70,19 @@ class MergeSort implements SortAlgorithm {
while (i <= mid && j <= right) { while (i <= mid && j <= right) {
if (temp[i].compareTo(temp[j]) <= 0) { if (temp[i].compareTo(temp[j]) <= 0) {
arr[k] = temp[i]; arr[k++] = temp[i++];
i++;
} }
else { else {
arr[k] = temp[j]; arr[k++] = temp[j++];
j++;
} }
k++;
} }
while (i <= mid) { while (i <= mid) {
arr[k] = temp[i]; arr[k++] = temp[i++];
i++;
k++;
} }
while (j <= right) { while (j <= right) {
arr[k] = temp[j]; arr[k++] = temp[j++];
j++;
k++;
} }
} }