Created
October 13, 2015 02:22
-
-
Save gnuvince/152cf2e304935b2faa08 to your computer and use it in GitHub Desktop.
This file contains 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 insertion_sort<T: PartialOrd>(xs: &mut Vec<T>) { | |
for i in 1..(xs.len() - 1) { | |
let mut j = i; | |
while j > 0 && xs[j-1] > xs[j] { | |
xs.swap(j, j-1); | |
j -= 1; | |
} | |
} | |
} | |
fn main() { | |
let mut v: Vec<i32> = vec![1, 3, 2, 3, 4]; | |
insertion_sort(&mut v); | |
for e in v { | |
println!("{}", e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment