sort_it/algorithms/
mod.rs

1pub mod bogosort;
2pub mod bubble_sort;
3pub mod gnome_sort;
4pub mod insertion_sort;
5pub mod merge_sort;
6pub mod quicksort;
7pub mod selection_sort;
8pub mod slowsort;
9pub mod stooge_sort;
10pub mod tree_sort;
11
12pub use bogosort::*;
13pub use bubble_sort::*;
14pub use gnome_sort::*;
15pub use insertion_sort::*;
16pub use merge_sort::*;
17pub use quicksort::*;
18pub use selection_sort::*;
19pub use slowsort::*;
20pub use stooge_sort::*;
21pub use tree_sort::*;
22
23/// A trait providing the `is_sorted` method on `Vec`'s implementing `T`.
24pub trait IsSorted<T: PartialEq + PartialOrd + Clone + Copy> {
25    /// Returns whether the given `Vec` is sorted or not.
26    fn is_sorted(&self) -> bool;
27}
28
29/// The trait implementation providing the `is_sorted` method.
30impl<T> IsSorted<T> for Vec<T>
31    where T: PartialEq + PartialOrd + Clone + Copy,
32{
33    fn is_sorted(&self) -> bool {
34        let mut is_sorted = true;
35
36        for i in 1..self.len() {
37            if self[i] < self[i-1] {
38                is_sorted = false;
39            }
40        }
41
42        return is_sorted;
43    }
44}
45