Update merge_sort.go

This commit is contained in:
GN-Yu 2022-12-30 13:21:40 -05:00 committed by GitHub
parent 1b71e74baa
commit 5d45f71167
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,11 +25,11 @@ func merge(nums []int, left, mid, right int) {
if i > left_end { if i > left_end {
nums[k] = tmp[j] nums[k] = tmp[j]
j++ j++
// 否则,若“右子数组已全部合并完”或“左子数组元素 < 右子数组元素”,则选取左子数组元素,并且 i++ // 否则,若“右子数组已全部合并完”或“左子数组元素 <= 右子数组元素”,则选取左子数组元素,并且 i++
} else if j > right_end || tmp[i] <= tmp[j] { } else if j > right_end || tmp[i] <= tmp[j] {
nums[k] = tmp[i] nums[k] = tmp[i]
i++ i++
// 否则,若“左子数组元素 > 右子数组元素”,则选取右子数组元素,并且 j++ // 否则,若“左右子数组都未全部合并完”且“左子数组元素 > 右子数组元素”,则选取右子数组元素,并且 j++
} else { } else {
nums[k] = tmp[j] nums[k] = tmp[j]
j++ j++