Skip to content

Instantly share code, notes, and snippets.

@evadnoob
Last active November 8, 2015 03:38
Show Gist options
  • Save evadnoob/e6d91e597178f4cad86d to your computer and use it in GitHub Desktop.
Save evadnoob/e6d91e597178f4cad86d to your computer and use it in GitHub Desktop.
Compiling sorting-algorithms v0.1.0 (file:///home/david/projects/sorting-algorithms)
Running target/debug/sorting_algorithms-abc13d1b10871a26
running 1 test
selection sort
unsorted [1, 88, 4, 9, 3, 2, 15, 12, 6, 7]
unsorted [1, 2, 3, 4, 6, 7, 9, 12, 15, 88]
test it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Doc-tests sorting-algorithms
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
fn selection_sort() {
println!("selection sort");
let mut unsorted = [1, 88, 4, 9, 3, 2, 15, 12, 6, 7];
for i in 0..unsorted.len() {
println!("i[{}] = {}", i, unsorted[i]);
for x in i..unsorted.len() {
if unsorted[x] < unsorted[i] {
let tmp = unsorted[i];
unsorted[i] = unsorted[x];
unsorted[x] = tmp;
}
}
}
println!("unsorted {:?}", unsorted);
}
#[test]
fn it_works() {
selection_sort();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment