algo/src/algorithms/bubblesort.rs
Jan Christian Grünhage 62f1b27dff refactor: cargo fmt
2017-08-27 17:26:01 +02:00

19 lines
493 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);
}
}