希尔排序
程序代码:
#include "stdio.h" void shellsort(int k[],int n) { int i, j, flag ,gap = n; int tmp; while(gap > 1){ gap = gap/2; for(i=1;i<=n-gap;i++){ j = i + gap; if(k[i]<k[j]){ tmp = k[i]; k[i] = k[j]; k[j] = tmp; } } } } main() { int i,a[11] = {-111,2,5,6,3,7,8,0,9,12,1}; 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]); /*输出排序后的结果*/ } 请问 for(i=1;i<=n-gap;i++){ j = i + gap; if(k[i]<k[j]){ tmp = k[i]; k[i] = k[j]; k[j] = tmp; } } 这个代码我不太明白啊!尤其是i<=n-grap我实在是看不懂