希尔排序
1 //希尔排序 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 void ShellSort(int a[], int n) 6 { 7 int gap, pos, j; 8 int tmp; 9 for (gap=n/2;gap>0;gap/=2) 10 { 11 for (pos=gap;pos<n;pos++) 12 { 13 tmp = a[pos]; 14 for (j=pos-gap;j>=0&&a[j]>tmp;j-=gap) 15 { 16 a[j + gap] = a[j]; 17 } 18 a[j + gap] = tmp; 19 } 20 } 21 } 22 int main() 23 { 24 int a[5] = { 1,6,3,5,2 }; 25 ShellSort(a, 5); 26 for (auto x:a) 27 { 28 cout << x << " "; 29 } 30 return 0; 31 }
道阻且长,行则将至

浙公网安备 33010602011771号