希尔排序(间接插入排序)

来源:互联网 发布:mac地址改不了 编辑:程序博客网 时间:2024/06/05 16:50
    #include <iostream>      using namespace std;            int a[10001];            void ShellSort(int a[],int n){          for(int gap = n/2; gap > 0; gap /= 2){        for(int i = gap; i < n;i++){        for(int j = i - gap;j >= 0 && a[j] > a[j+gap];j -= gap){        swap(a[j],a[j+gap]);        }        }        }    }            int main(){          int n;          while(cin>>n){              for(int i=0;i<n;i++){                  cin>>a[i];              }              ShellSort(a,n);              for(int i=0;i<n-1;i++){                  cout<<a[i]<<' ';              }              cout<<a[n-1]<<endl;          }          return 0;      }    

0 0