MCPcopy Index your code
hub / github.com/douchuan/algorithm / sort

Function sort

src/sort/shell.rs:7–26  ·  view source on GitHub ↗

希尔排序 (Shell's Sort) 又称“缩小增量排序”(Diminishing Increment Sort), 是直接插入排序算法的一种更高效的改进版本。希尔排序是 非稳定排序算法。该方法因 D.L.Shell 于 1959 年提出而得名。

(a: &mut [T])

Source from the content-addressed store, hash-verified

5//! 非稳定排序算法。该方法因 D.L.Shell 于 1959 年提出而得名。
6
7pub fn sort<T>(a: &mut [T])
8where
9 T: Ord + Copy,
10{
11 let len = a.len();
12 let mut gap = len;
13 while gap > 1 {
14 gap /= 2;
15
16 for i in gap..len {
17 let insert_v = a[i];
18 let mut j = i;
19 while j >= gap && insert_v < a[j - gap] {
20 a[j] = a[j - gap];
21 j -= gap;
22 }
23 a[j] = insert_v;
24 }
25 }
26}

Callers 15

small_merge_v1Function · 0.50
large_merge_v1Function · 0.50
eq_data_merge_v1Function · 0.50
small_merge_v2Function · 0.50
large_merge_v2Function · 0.50
eq_data_merge_v2Function · 0.50
small_merge_v3Function · 0.50
large_merge_v3Function · 0.50

Calls 1

lenMethod · 0.45

Tested by 6

mergeFunction · 0.40
LSD_radix_sortFunction · 0.40
MSD_radix_sortFunction · 0.40
quick3strFunction · 0.40
quick3wayFunction · 0.40
sorted_dataFunction · 0.40