#include <stdio.h> #include <stdlib.h> void shellSort(int arr[],int n) { int dk,i,j,p; for(dk=n/2;dk>=1;dk=dk/2) { for(i=dk+1;i<n;i++) { if(arr[i]<arr[i-dk]) { p=arr[i]; for(j=i-dk;j>0&&p<arr[j];j-=dk) arr[j+dk]=arr[j]; arr[j+dk]=p; } } } } int main() { int arr[13]={2,15,24,6,8,21,5,23,12,16,56,34,18}; int n=sizeof(arr)/sizeof(arr[0]); shellSort(arr,n); for (int i = 0; i < n; i++) { printf("%d ",arr[i]); } return 0; }
标签:arr,排序,dk,int,希尔,include From: https://www.cnblogs.com/simpleset/p/17871668.html