天天看點

希爾排序

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 }      

有的要别人來設定目标,有的給别人設定目标;

有的需要感情支援生活,有的需要意志支援生活。