希尔排序

 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         }

 

posted @ 2012-12-27 17:59  宁静.致远  阅读(177)  评论(0编辑  收藏  举报