Skip to content

Commit 8677246

Browse files
authored
Merge pull request TheAlgorithms#681 from guoxiaoxu/master
Update MergeSort.java
2 parents f88287e + 21a7b9d commit 8677246

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

Sorts/MergeSort.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,19 @@ private static <T extends Comparable<T>> void merge(T[] arr, T[] temp, int left,
7070

7171
while (i <= mid && j <= right) {
7272
if (temp[i].compareTo(temp[j]) <= 0) {
73-
arr[k] = temp[i];
74-
i++;
73+
arr[k++] = temp[i++];
7574
}
7675
else {
77-
arr[k] = temp[j];
78-
j++;
76+
arr[k++] = temp[j++];
7977
}
80-
k++;
8178
}
8279

8380
while (i <= mid) {
84-
arr[k] = temp[i];
85-
i++;
86-
k++;
81+
arr[k++] = temp[i++];
8782
}
8883

8984
while (j <= right) {
90-
arr[k] = temp[j];
91-
j++;
92-
k++;
85+
arr[k++] = temp[j++];
9386
}
9487
}
9588

0 commit comments

Comments
 (0)