java/12_sorts/MergeSort
This commit is contained in:
parent
91826a79fb
commit
373b935efb
@ -15,8 +15,8 @@ public class MergeSort {
|
|||||||
// 递归终止条件
|
// 递归终止条件
|
||||||
if (p >= r) return;
|
if (p >= r) return;
|
||||||
|
|
||||||
// 取p到r之间的中间位置q
|
// 取p到r之间的中间位置q,防止(p+r)的和超过int类型最大值
|
||||||
int q = (p+r)/2;
|
int q = p + (r - p)/2;
|
||||||
// 分治递归
|
// 分治递归
|
||||||
mergeSortInternally(a, p, q);
|
mergeSortInternally(a, p, q);
|
||||||
mergeSortInternally(a, q+1, r);
|
mergeSortInternally(a, q+1, r);
|
||||||
|
Loading…
Reference in New Issue
Block a user