#include<stdlib.h>
#include<stdio.h>
using namespace std;
void Shell_Sort(int* arry, int count)
{
int i = 0;
int j = 0;
int k = -1;
int tmp = -1;
int gap = count;
do
{
gap = gap / 3 + 1;
for ( i = gap; i < count; i+=gap)
{
k = i;
tmp = arry[k];
for (j=i-gap; i >=0&&arry[j]>tmp; j-=gap)
{
arry[j + gap] = arry[j];
k = j;
}
arry[k] = tmp;
}
} while (gap>1);
}
void main()
{
int arry[] = { 12,20,45,25,35,1,2,54,52 };
int count = sizeof(arry) / sizeof(*arry);
printf("arry数组个数:%d\n", count);
for (int i = 0; i < count; i++)
{
printf("%d ", arry[i]);
}
printf("\n排序之前");
Shell_Sort(arry, count);
for (int i = 0; i < count; i++)
{
printf("%d ", arry[i]);
}
printf("\n排序之后");
system("pause");
}
排序算法-希尔排序
最新推荐文章于 2023-04-20 16:50:38 发布