#include <stdlib.h>
#include <stdio.h>
void print(int arr[], int n)
{
int i;
printf("\n");
for (i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
void shellSort(int arr[], int n)
{
int k, i, j, p;
for (k = n / 2; k > 0; k /= 2)//增量循环
{
for (p = 0; p < k; p++)//分组
{
for(i=p;i<n-k;i+=k){//插入排序
int current=arr[k+i];
for(j=i+k;j>p&&arr[j-k]>current;j-=k)
{
arr[j]=arr[j-k];
}
arr[j]=current;
}
}
}
}
int main(int argc, char **argv)
{
int arr[] = {1, 4, 2, 3,324,23,4,23,423,34,23,4};
int size = sizeof(arr) / sizeof(int);
print(arr, size);
shellSort(arr, size);
print(arr, size);
}