shell 排序是插入排序的一种
在排序中需要设置步长 建立虚拟的数组 并对这些切选取出来的数组进行插入排序
代码如下:
public static void shellSort(int[] array){
int step = array.length;
do{
step = step/2; //设置步调 步长为1 的时候结束
for(int i=step;i<array.length;i++){ //遍历数组 根据步长遍历
if(array[i]<array[i-step]){ //判断 虚拟数组 并进行插入排序
int temp = array[i];//保存交换的数值
int j = 0;//保存交换的坐标
for(j=i-step;(j>=0&&temp<array[j]);j-=step){ //向后移位
array[j+step] = array[j];
}
array[j+step] = temp;// 交换数据
}
}
}while(step>1);
}