1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// A single pass, no-nonsense sorting algorithm with O(n) complexity that
/// removes elements until the value is sorted.
///
/// This is a reference to [Joseph Stalin]'s horrible regime over Russia.
///
/// > Official records reveal 799,455 documented executions in the Soviet Union
/// > between 1921 and 1953; 681,692 of these were carried out between 1937 and
/// > 1938, the years of the [Great Purge].
///
/// # Source
///
/// <img src="https://i.redd.it/x9triplll1v11.jpg" width="360px">
///
/// <q>I came up with a single pass O(n) sort algorithm I call StalinSort. You
/// iterate down the list of elements checking if they're in order. Any element
/// which is out of order is eliminated. At the end you have a sorted list.</q>
/// <br>
/// <i>- mathew ✅ (@mathew@mastodon.social)</i>
///
/// # Examples
///
/// These methods can be used similarly to how one would use [`sort`].
///
/// An extra `stalin_sorted` method is added for convenience for when the type
/// implements [`Clone`].
///
/// ```
/// use bad::StalinSort;
///
/// # #[cfg(feature = "std")] {
/// let values = vec![1, 2, 3, 0, 42, -2];
/// assert_eq!(values.stalin_sorted(), [1, 2, 3, 42]);
/// # }
/// ```
///
/// [Joseph Stalin]: https://en.wikipedia.org/wiki/Joseph_Stalin
/// [Great Purge]: https://en.wikipedia.org/wiki/Great_Purge
/// [`sort`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort
/// [`Clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html