标签:blank length IV 希尔排序 .com sort span color www
插入排序的升级,先设比较大的步长进行插入排序,然后步长逐步减少,最后保证步长为1的一次插入排序即可
package com.bsc.algorithm.sort.shell; import com.bsc.algorithm.sort.insert.InsertSort; /** * 希尔排序 * * @author bsc * */ public class ShellSort<T extends Comparable<T>> extends InsertSort<T> { protected void sort(T[] data, int cr) { int length = data.length; //初始步长为数组长度的一半 int increment = length / 2; while (increment > 0) { //进行插入排序 sort(data, cr, increment); //步长每次减少一半(保证最后一次排序步长为1) increment = increment / 2; } } }
标签:blank length IV 希尔排序 .com sort span color www
原文地址:https://www.cnblogs.com/bsc2012/p/9212485.html