From d4d281cd67e2495e32872f314e5cc8a92383506c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E6=98=A5=E9=A3=8E?= <77157236+night-cruise@users.noreply.github.com> Date: Sat, 27 Jan 2024 19:42:19 +0800 Subject: [PATCH] Fix the issue of discussion 514 (#1064) --- codes/rust/chapter_sorting/selection_sort.rs | 3 +++ 1 file changed, 3 insertions(+) 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 {