标签:
#include<stdio.h>
#include<stdlib.h>
void shellSort(int r[],int len);
int main(void)
{
int r[] = {45,20,80,40,26,58,66,70};
shellSort(r,8);
system("PAUSE");
}
void shellSort(int r[],int len)
{
int d = len;
int i,j;
while(d > 1)
{
d = (d+1)/2;
//关键代码
for(i = 0;i < len-d;i++)
{
if(r[i+d] < r[i])
{
int temp;
temp = r[i+d];
r[i+d] = r[i];
r[i] = temp;
}
}
printf("\nd=%d\t",d);
for(j = 0;j < 8;j++ )
{
printf("%d,",r[j]);
}
}
printf("\nresults:");
for(j = 0;j < 8;j++ )
{
printf("%d,",r[j]);
}
}
标签:
原文地址:http://www.cnblogs.com/100114jerro/p/4998749.html