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
58
59
pub fn slow_sort<T: PartialOrd>(input: &mut [T]) {
if input.len() < 2 {return;}
slow_sort_sorting(input, 0, input.len() - 1);
}
fn slow_sort_sorting<T: PartialOrd>(input: &mut [T], start: usize, end: usize) {
if start >= end {return;}
let mid = (start + end) / 2;
slow_sort_sorting(input, start, mid);
slow_sort_sorting(input, mid + 1, end);
if input[end] < input[mid] {input.swap(end, mid);}
slow_sort_sorting(input, start, end - 1);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_slow() {
let mut vector_in = vec![10, 20, 11, 24];
slow_sort(&mut vector_in);
debug_assert_eq!(vector_in, vec![10, 11, 20, 24]);
}
#[test]
fn test_slow_empty() {
let mut vector_in:Vec<i32> = vec![];
slow_sort(&mut vector_in);
debug_assert_eq!(vector_in, &[]);
}
#[test]
fn test_slow_len1() {
let mut vector_in = vec![1];
slow_sort(&mut vector_in);
debug_assert_eq!(vector_in, vec![1]);
}
}