18 lines
492 B
Rust
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);
|
|
}
|
|
} |