通过比较相距一定间隔的元素,各趟比较所用的距离随着算法的进行而减小,直到只比较相邻的元素的最后一趟位置。
初始间隔一般为 n/2 (n为元素个数)
如图所示:
class Test{ /** * 希尔排序基础实现 * @param array 目标数组 * @param n 初始间距 * @return */ public static int[] shellSort(int[] array,int n) { for