希尔排序 C#

1 
 1  class Program

 2     {

 3         static void Main(string[] args)
 4         {
 5             int[] iArrary = new int[] { 151361055992871234753347 };
 6             ShellSorter sh = new ShellSorter();
 7             sh.Sort(iArrary);
 8             for (int m = 0; m < iArrary.Length; m++)
 9                 Console.Write("{0} ", iArrary[m]);
10             Console.ReadLine();
11         }
12     }

2.

 1   class ShellSorter
 2     {
 3         /// <summary>
 4         /// 希尔排序
 5         /// </summary>
 6         public void Sort(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         }

25     } 

 

posted @ 2013-05-17 14:29  yellowshorts  阅读(98)  评论(0编辑  收藏  举报