void shellsort(int k[],int n)
{
int i, j, flag ,gap = n;
int tmp;
while(gap > 1){
gap = gap/2; /*增量减半*/
do{ /*冒泡*/
flag = 0;
for(i=1;i<=n-gap;i++){
j = i + gap;
if(k[i]
tmp = k[i];
k[i] = k[j];
k[j] = tmp;
flag = 1;
}
}
}while(flag !=0);
}
}
void shell()
{
int i,a[11] = {-111,2,5,6,3,7,8,0,9,12,1}; /*初始化序列,a[0]任意*/
printf("The orginal data array is\n") ;
for(i=1;i<=10;i++) /*执行*/
printf("%d ",a[i]);
shellsort(a,10); /*希尔*/
printf("\nThe result of Shell's sorting for the array is\n");
for(i=1;i<=10;i++)
printf("%d ",a[i]); /*打印*/
}
阅读(1406) | 评论(0) | 转发(0) |