C#算法(三)希尔排序

C#算法(三)希尔排序


Author: solarsoft  &;nbspFrom:Internet


                朋友们,我最近加紧写C#的一些算法。选择排序,插入算法是我已经推出的。现推出希尔排序.今后,如有时间我将依次推出其它的算法编写。
  希尔排序是将组分段,进行插入排序.
  对想提高C#语言编程能力的朋友,我们可以互相探讨一下。
  如:下面的程序,并没有实现多态,来,帮它实现一下。using System;
  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 class MainClass
  {
      public static void Main()
      {
      int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47};
      ShellSorter sh=new ShellSorter();
      sh.Sort(iArrary);
      for(int m=0;m<=13;m  )
      Console.WriteLine("{0}",iArrary[m]); 
        }
  }
  已经编译通过.
 
    (2005-9-10:09:13)
 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 警告:持续变种木马正在发起农历新年攻势!
 您可能对 [C#] 的这些文章也感兴趣:
DotMSN机器人自动掉线的问题
当编程语言不再是最容易的部分—有关Lambda + LINQ之后的C#
利用 C# 实现任务栏通知窗口
实验分析C#中三种计时器使用异同点
C# 3.0 之新特性总结
WinForm App自动更新(Live Update)架构
C#中使用晚绑定实现压缩Access数据库
小议Focus()方法
WPF C# Ribbon Control Library
Hashtable的自定义排序
C# 3.0 Cookbook出版
dynamic lookup将变得很强大