[Rust] Normalize mid calculation in case overflow (#1363)

* Normalize mid calculate in case overflow

* Change ALL language

* Update merge_sort.py

* Update merge_sort.zig

* Update binary_search_tree.zig

* Update binary_search_recur.py

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
rongyi
2024-05-18 18:19:19 +08:00
committed by GitHub
parent 0e221540a3
commit 21be3fdaf8
41 changed files with 57 additions and 59 deletions

View File

@ -48,7 +48,7 @@ fn merge_sort(nums: &mut [i32], left: usize, right: usize) {
}
// 划分阶段
let mid = (left + right) / 2; // 计算中点
let mid = left + (right - left) / 2; // 计算中点
merge_sort(nums, left, mid); // 递归左子数组
merge_sort(nums, mid + 1, right); // 递归右子数组

View File

@ -35,9 +35,7 @@ fn counting_sort_digit(nums: &mut [i32], exp: i32) {
counter[d] -= 1; // 将 d 的数量减 1
}
// 使用结果覆盖原数组 nums
for i in 0..n {
nums[i] = res[i];
}
nums.copy_from_slice(&res);
}
/* 基数排序 */