Created
January 1, 2020 15:36
-
-
Save aita/82c3cfcfd41dbd814d4a3511d4e2dba5 to your computer and use it in GitHub Desktop.
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 selection_sort<T: PartialOrd>(v: &mut [T]) { | |
| let len = v.len(); | |
| for i in 0..len - 1 { | |
| let mut k = i; | |
| for j in i..len { | |
| if v[k] > v[j] { | |
| k = j; | |
| } | |
| } | |
| if i != k { | |
| v.swap(i, k); | |
| } | |
| } | |
| } | |
| fn main() { | |
| let mut number_list = vec![34, 50, 25, 100, 65]; | |
| selection_sort(&mut number_list); | |
| println!("{:?}", number_list) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment