1 #include2 #include 3 4 typedef struct 5 { 6 int *data; 7 int length; 8 }Sqlist; 9 10 11 /*顺序表的初始化*/12 void InitList(Sqlist &L, int l)13 {14 L.data = (int*)malloc((l+1)*sizeof(int));15 L.length = 0;16 }17 18 void CreateLList(Sqlist &L, int *a, int l)19 {20 L.length = 1;21 for(int i=1; i<=l; i++)22 {23 L.data[i] = a[i-1];24 L.length++;25 }26 }27 28 29 /*30 实现希尔排序(缩小增量排序)31 data[]增量序列32 */33 void ShellInsert(Sqlist &L, int dk)34 {35 int j, i;36 for(i = dk + 1; i 0 && (L.data[0] < L.data[j]); j-=dk)42 {43 L.data[j+dk] = L.data[j]; 44 }45 L.data[j+dk] = L.data[0];46 }47 }48 }49 50 void ShellSort(Sqlist &L, int dlta[], int t)51 {52 for (int k = 0; k < t; k++)53 {54 ShellInsert(L,dlta[k]); //一趟增量为dlta[k]的插入排序55 }56 }57 58 59 void DisplayList(Sqlist L)60 {61 for(int i = 1; i