198e154495
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
19 lines
478 B
Rust
19 lines
478 B
Rust
use sorting::Algorithm;
|
|
|
|
pub struct Sort;
|
|
|
|
impl Algorithm for Sort {
|
|
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);
|
|
}
|
|
}
|