MCPcopy Create free account
hub / github.com/142vip/408CSFamily / ShellSort

Function ShellSort

code/ds/ShellSort.cpp:3–24  ·  view source on GitHub ↗

希尔排序【伪代码】

Source from the content-addressed store, hash-verified

1
2// 希尔排序【伪代码】
3void ShellSort(ElemType Arr[] , int n){
4 // k是增量
5 for(k=n/2;k>=1;k=k/2){
6
7 // 增量子表进行直接插入排序
8 for(i=k+1;i<=n;++i){
9
10 if(Arr[i].key<Arr[i-k].key){
11
12 // 元素暂存
13 Arr[0]=Arr[i];
14
15 for(j=i-k;j>0&&Arr[0].key<Arr[j].key;j-=k){
16 // 记录后移,查找插入的位置
17 Arr[j+k]=Arr[j]
18 }
19 // 插入
20 Arr[j+k]=Arr[0]
21 }
22 }
23 }
24}
25
26
27void ShellSortEnhance(ElemType Arr[] , int n){

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected