|
|
|
@ -142,7 +142,7 @@ comments: true
|
|
|
|
|
if (left >= right)
|
|
|
|
|
return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
int mid = (left + right) / 2; // 计算中点
|
|
|
|
|
int mid = left + (right - left) / 2; // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -186,7 +186,7 @@ comments: true
|
|
|
|
|
if (left >= right)
|
|
|
|
|
return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
int mid = (left + right) / 2; // 计算中点
|
|
|
|
|
int mid = left + (right - left) / 2; // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -229,7 +229,7 @@ comments: true
|
|
|
|
|
// 终止条件
|
|
|
|
|
if (left >= right) return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
int mid = (left + right) / 2; // 计算中点
|
|
|
|
|
int mid = left + (right - left) / 2; // 计算中点
|
|
|
|
|
MergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
MergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -282,7 +282,7 @@ comments: true
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 划分阶段
|
|
|
|
|
mid := (left + right) / 2
|
|
|
|
|
mid := left + (right - left) / 2
|
|
|
|
|
mergeSort(nums, left, mid)
|
|
|
|
|
mergeSort(nums, mid+1, right)
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -335,7 +335,7 @@ comments: true
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 划分阶段
|
|
|
|
|
let mid = (left + right) / 2 // 计算中点
|
|
|
|
|
let mid = left + (right - left) / 2 // 计算中点
|
|
|
|
|
mergeSort(nums: &nums, left: left, right: mid) // 递归左子数组
|
|
|
|
|
mergeSort(nums: &nums, left: mid + 1, right: right) // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -381,7 +381,7 @@ comments: true
|
|
|
|
|
// 终止条件
|
|
|
|
|
if (left >= right) return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
let mid = Math.floor((left + right) / 2); // 计算中点
|
|
|
|
|
let mid = Math.floor(left + (right - left) / 2); // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -427,7 +427,7 @@ comments: true
|
|
|
|
|
// 终止条件
|
|
|
|
|
if (left >= right) return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
let mid = Math.floor((left + right) / 2); // 计算中点
|
|
|
|
|
let mid = Math.floor(left + (right - left) / 2); // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -470,7 +470,7 @@ comments: true
|
|
|
|
|
// 终止条件
|
|
|
|
|
if (left >= right) return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
int mid = (left + right) ~/ 2; // 计算中点
|
|
|
|
|
int mid = left + (right - left) ~/ 2; // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -525,7 +525,7 @@ comments: true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 划分阶段
|
|
|
|
|
let mid = (left + right) / 2; // 计算中点
|
|
|
|
|
let mid = left + (right - left) / 2; // 计算中点
|
|
|
|
|
merge_sort(nums, left, mid); // 递归左子数组
|
|
|
|
|
merge_sort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
|
|
|
|
@ -574,7 +574,7 @@ comments: true
|
|
|
|
|
if (left >= right)
|
|
|
|
|
return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
int mid = (left + right) / 2; // 计算中点
|
|
|
|
|
int mid = left + (right - left) / 2; // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -619,7 +619,7 @@ comments: true
|
|
|
|
|
// 终止条件
|
|
|
|
|
if (left >= right) return // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
val mid = (left + right) / 2 // 计算中点
|
|
|
|
|
val mid = left + (right - left) / 2 // 计算中点
|
|
|
|
|
mergeSort(nums, left, mid) // 递归左子数组
|
|
|
|
|
mergeSort(nums, mid + 1, right) // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
@ -671,7 +671,7 @@ comments: true
|
|
|
|
|
# 当子数组长度为 1 时终止递归
|
|
|
|
|
return if left >= right
|
|
|
|
|
# 划分阶段
|
|
|
|
|
mid = (left + right) / 2 # 计算中点
|
|
|
|
|
mid = left + (right - left) / 2 # 计算中点
|
|
|
|
|
merge_sort(nums, left, mid) # 递归左子数组
|
|
|
|
|
merge_sort(nums, mid + 1, right) # 递归右子数组
|
|
|
|
|
# 合并阶段
|
|
|
|
@ -725,7 +725,7 @@ comments: true
|
|
|
|
|
// 终止条件
|
|
|
|
|
if (left >= right) return; // 当子数组长度为 1 时终止递归
|
|
|
|
|
// 划分阶段
|
|
|
|
|
var mid = (left + right) / 2; // 计算中点
|
|
|
|
|
var mid = left + (right - left) / 2; // 计算中点
|
|
|
|
|
try mergeSort(nums, left, mid); // 递归左子数组
|
|
|
|
|
try mergeSort(nums, mid + 1, right); // 递归右子数组
|
|
|
|
|
// 合并阶段
|
|
|
|
|