Skip to content

Commit 172998b

Browse files
author
wzx
committed
the second array may have residual elements.
1 parent 3e64771 commit 172998b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sorts/src/sort/MergeSort.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ private static <T extends Comparable<T>> void merge(T[] arr, T[] temp, int left,
8585
i++;
8686
k++;
8787
}
88+
89+
while (j <= right) {
90+
arr[k] = temp[j];
91+
j++;
92+
k++;
93+
}
8894
}
8995

9096
// Driver program

0 commit comments

Comments
 (0)