- using System;
- namespace ShellSorter
- {
- public class ShellSorter
- {
- public void Sort(int[] list)
- {
- int inc;
- for (inc = 1; inc <= list.Length / 9; inc = 3 * inc + 1) ;
- for (; inc > 0; inc /= 3)
- {
- for (int i = inc + 1; i <= list.Length; i += inc)
- {
- int t = list[i - 1];
- int j = i;
- while ((j > inc) && (list[j - inc - 1] > t))
- {
- list[j - 1] = list[j - inc - 1];
- j -= inc;
- }
- list[j - 1] = t;
- }
- }
- }
- public static void Main(string[] args)
- {
- int[] iarrary = new int[] { 1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };
- ShellSorter ss = new ShellSorter();
- ss.Sort(iarrary);
- for (int m = 0; m < iarrary.Length; m++)
- Console.Write("{0} ", iarrary[m]);
- Console.WriteLine();
- Console.ReadLine();
- }
- }
- }
C# 希尔排序
最新推荐文章于 2024-04-29 11:42:43 发布