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
83 lines
1.7 KiB
Rust
83 lines
1.7 KiB
Rust
mod sorting;
|
|
|
|
use sorting::*;
|
|
use sorting::Algorithm;
|
|
|
|
fn main() {
|
|
demo_sorting();
|
|
}
|
|
|
|
fn demo_sorting() {
|
|
let unsorted: Vec<i32> = vec![
|
|
2498,
|
|
29687,
|
|
24,
|
|
94545,
|
|
8,
|
|
51,
|
|
152,
|
|
871,
|
|
5,
|
|
6557,
|
|
216,
|
|
75986,
|
|
48,
|
|
526,
|
|
15,
|
|
6,
|
|
78,
|
|
];
|
|
|
|
println!("Unsorted array: {:?}", unsorted);
|
|
println!(
|
|
"Bubblesort : {:?}",
|
|
match bubble::Sort::sort(unsorted.clone()) {
|
|
Ok(v) => v,
|
|
Err(e) => {
|
|
println!("Something went wrong! {}", e);
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
println!(
|
|
"Selectionsort : {:?}",
|
|
match selection::Sort::sort(unsorted.clone()) {
|
|
Ok(v) => v,
|
|
Err(e) => {
|
|
println!("Something went wrong! {}", e);
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
println!(
|
|
"Insertionsort : {:?}",
|
|
match insertion::Sort::sort(unsorted.clone()) {
|
|
Ok(v) => v,
|
|
Err(e) => {
|
|
println!("Something went wrong! {}", e);
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
println!(
|
|
"Mergesort : {:?}",
|
|
match merge::Sort::sort(unsorted.clone()) {
|
|
Ok(v) => v,
|
|
Err(e) => {
|
|
println!("Something went wrong! {}", e);
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
println!(
|
|
"Quicksort : {:?}",
|
|
match quick::Sort::sort(unsorted.clone()) {
|
|
Ok(v) => v,
|
|
Err(e) => {
|
|
println!("Something went wrong! {}", e);
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
}
|