//希尔排序(分组式的直接插入排序)
void shell_group_pass(int* buf, int len, int increment) {
printf("shell group pass %d\n", increment);
for(int i=0; i for(int j=i+increment; j int now = buf[j];
if(now > buf[j-increment])continue;
int k;
for(k=j-increment; k>=0; k-=increment) {
if(buf[k] > now)buf[k+increment] = buf[k];
else break;
}
buf[k+increment] = now;
}
}
}
void shell_sort(int* buf, int len) {
int increment = 12;
do {
increment = increment/3+1;
shell_group_pass(buf, len, increment);
} while(increment > 1);
}
阅读(1294) | 评论(0) | 转发(0) |