希尔排序
1 /// <summary> 2 /// 希尔排序 3 /// 插入排序改进版本:分区插入 4 /// </summary> 5 /// <param name="list"></param> 6 private static int[] ShellSort(int[] list) 7 { 8 int inc; 9 for (inc = 1; inc <= list.Length / 9; inc = 3 * inc + 1) ; 10 for (; inc > 0; inc /= 3) 11 { 12 for (int i = inc + 1; i <= list.Length; i += inc) 13 { 14 int t = list[i - 1]; 15 int j = i; 16 while ((j > inc) && (list[j - inc - 1] > t)) 17 { 18 list[j - 1] = list[j - inc - 1]; 19 j -= inc; 20 } 21 list[j - 1] = t; 22 } 23 } 24 return list; 25 }
工欲善其事,必先利其器。