Skip to content

Commit

Permalink
Merge pull request wangzheng0822#95 from PansonPanson/master
Browse files Browse the repository at this point in the history
java/12_sorts/MergeSort
  • Loading branch information
wangzheng0822 authored Oct 25, 2018
2 parents d6aa5b8 + 373b935 commit 18558ab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions java/12_sorts/MergeSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ private static void mergeSortInternally(int[] a, int p, int r) {
// 递归终止条件
if (p >= r) return;

// 取p到r之间的中间位置q
int q = (p+r)/2;
// 取p到r之间的中间位置q,防止(p+r)的和超过int类型最大值
int q = p + (r - p)/2;
// 分治递归
mergeSortInternally(a, p, q);
mergeSortInternally(a, q+1, r);
Expand Down

0 comments on commit 18558ab

Please sign in to comment.