#include<iostream> using namespace std; void insertDxSort(int *data,int start,int end,int dx) { //以增量dx进行增量排序 int key=0; int j=0; for(int i=start+dx;i<=end;i+=dx) { key=data[i]; j=i-dx; while(j>=start&&data[j]>key) { data[j+dx]=data[j]; j-=dx; } data[j+dx]=key; } } void shellSort(int *data,int start,int end,int dx) { for(int i=0;i!=dx;i++) insertDxSort(data,start+i, end, dx); } void shellSortCore(int *data,int start,int end) { shellSort(data,start,end,3); shellSort(data,start,end,2); shellSort(data,start,end,1); } int main() { int data[]={8,21,2,34,0,211,56,2,6}; shellSortCore(data,0,8); for(int i=0;i<=8;i++) cout<<data[i]<<" "; }
原文地址:http://blog.csdn.net/hero_zouzongling/article/details/45770641