1 #include <stdio.h> 2 3 typedef int ElementType; 4 5 void SwapTwoNum(ElementType *Num_1,ElementType *Num_2) 6 { 7 int NumTemp = *Num_1; 8 *Num_1 = *Num_2; 9 *Num_2 = NumTemp; 10 } 11 12 void ShellSort(ElementType *Array,int ArrayLen) 13 { 14 int i,j; 15 int Gap; 16 for(Gap = ArrayLen/2;Gap > 0;Gap /= 2) 17 { 18 for(i = Gap;i < ArrayLen;i ++) 19 { 20 for(j = i - Gap;j >= 0 && Array[j] > Array[j+Gap];j -= Gap) 21 { 22 SwapTwoNum(&Array[j],&Array[j+Gap]); 23 } 24 } 25 } 26 } 27 28 int main() 29 { 30 ElementType TestArray[10] = {8,9,2,4,1,2,5,9,3,7}; 31 ShellSort(TestArray,10); 32 int i; 33 for(i = 0;i < 10;i ++) 34 { 35 printf("%d ",TestArray[i]); 36 } 37 printf(" "); 38 return 0; 39 }