algo/src/sorting/selection.rs
Jan Christian Grünhage 198e154495 feat: demo all algorithms
Add demo code for all currently implemented algorithms, as well as a refactoring of the package structure.
Rename of the mistakenly called insertion sort, which was actually selection sort.

Fixes #1 and Fixes #2
2017-08-29 10:08:42 +02:00

19 lines
474 B
Rust

use sorting::*;
pub struct Sort;
impl Algorithm for Sort {
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;
}
}
vector = rotate(vector, i, smallest_index);
}
return Ok(vector);
}
}