Skip to content

Instantly share code, notes, and snippets.

@xiabingquan
Created February 11, 2025 14:37
Show Gist options
  • Save xiabingquan/3d2a3e284db0c5c8e788de64d1f16b72 to your computer and use it in GitHub Desktop.
Save xiabingquan/3d2a3e284db0c5c8e788de64d1f16b72 to your computer and use it in GitHub Desktop.
A minimal example of selective sort in Rust
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