diff --git a/codes/rust/chapter_sorting/selection_sort.rs b/codes/rust/chapter_sorting/selection_sort.rs index 6e30a7b21..54265b0a4 100644 --- a/codes/rust/chapter_sorting/selection_sort.rs +++ b/codes/rust/chapter_sorting/selection_sort.rs @@ -8,6 +8,9 @@ include!("../include/include.rs"); /* 选择排序 */ fn selection_sort(nums: &mut [i32]) { + if nums.is_empty() { + return; + } let n = nums.len(); // 外循环:未排序区间为 [i, n-1] for i in 0..n-1 {