algo/src/algorithms/bubblesort.rs
Jan Christian Grünhage c2da90822c feat: add bubblesort
2017-08-27 13:27:35 +02:00

18 lines
466 B
Rust

use algorithms::Algorithm;
pub struct Bubblesort;
impl Algorithm for Bubblesort {
fn sort(mut vector: Vec<i32>) -> Vec<i32> {
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 vector;
}
}