algo/src/algorithms/bubblesort.rs
Jan Christian Grünhage df06ce02c9 feat: add mergesort
2017-08-27 15:51:31 +02:00

18 lines
492 B
Rust

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