mod bubble;
mod insertion;
mod quick;
mod selection;
pub use bubble::Bubble;
pub use insertion::Insertion;
pub use quick::Quick;
pub use selection::Selection;
pub trait Sorter {
fn sort<T>(&self, slice: &mut [T])
where
T: Ord;
}
#[cfg(test)]
mod tests {
use super::*;
struct StdSorter;
impl Sorter for StdSorter {
fn sort<T>(&self, slice: &mut [T])
where
T: Ord,
{
slice.sort();
}
}
#[test]
fn std() {
let mut items = vec![4, 2, 3, 1];
StdSorter.sort(&mut items);
assert_eq!(items, &[1, 2, 3, 4]);
}
}