algo/src/algorithms/insertionsort.rs
Jan Christian Grünhage 15d253d49c chore: remove debug log
2017-08-27 17:36:44 +02:00

25 lines
723 B
Rust

use algorithms::Algorithm;
pub struct Insertionsort;
impl Algorithm for Insertionsort {
fn sort(mut vector: Vec<i32>) -> Result<Vec<i32>, &'static str> {
for i in 0..vector.len() {
let mut smallest_index = i;
for j in i..vector.len() {
if vector[j] < vector[smallest_index] {
smallest_index = j;
}
}
if i != smallest_index {
let smallest_value = vector[smallest_index];
for j in (i..(smallest_index)).rev() {
vector[j + 1] = vector[j];
}
vector[i] = smallest_value;
}
}
return Ok(vector);
}
}