Created
February 11, 2025 14:37
-
-
Save xiabingquan/3d2a3e284db0c5c8e788de64d1f16b72 to your computer and use it in GitHub Desktop.
A minimal example of selective sort in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn selective_sort<T: Ord + Clone>(arr: &mut [T]) { | |
let n = arr.len(); | |
for i in 0..n { | |
let mut max_val = arr[i].clone(); | |
let mut max_idx = i; | |
for j in i..n { | |
if arr[j] > max_val { | |
max_val = arr[j].clone(); | |
max_idx = j; | |
} | |
} | |
arr.swap(i, max_idx); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment