package Utils.Sort;
/**
*希尔排序,要求待排序的数组必须实现Comparable接口
*/
public class ShellSort implements SortStrategy
{ private int[] increment;
/**
*利用希尔排序算法对数组obj进行排序
*/
public void sort(Comparable[] obj)
{ if (obj == null)
{ throw new NullPointerException("The argument can not be null!");
}
//初始化步长
initGap(obj);
//步长依次变化(递减)
for (int i = increment.length - 1 ;i = 0 ;i-- )
{ int step = increment[i];
//由步长位置开始
for (int j = step ;j
{ Comparable tmp;
//假如后面的小于前面的(相隔step),则与前面的交换
for (int m = j ;m = step ;m = m - step )
{ if (obj[m].compareTo(obj[m - step])