希尔排序
1 /** 2 * 功能:希尔排序 3 */ 4 public class ShellSort { 5 6 public int[] shellSort(int[] array) { 7 8 int increment = array.length; 9 int temp = 0; 10 int index = 0; 11 12 do { 13 // 分组的步长 14 increment = increment / 3 + 1; 15 16 for (int i = increment; i < array.length; i++) { 17 18 // 每一组数进行插入排序 19 temp = array[i]; 20 index = i; 21 for (int j = i - increment; j >= 0; j -= increment) { 22 if (array[j] > temp) { 23 array[j + increment] = array[j]; 24 index = j; 25 } 26 } 27 array[index] = temp; 28 } 29 30 } while (increment > 1); 31 32 return array; 33 } 34 }