当前位置:开发者网络 >> 技术教程 >> .NET教程 >> 算法/线程 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
C#算法----(二)插入排序
作者:未知
日期:2003-07-12
人气:
投稿:Andy.m(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
using System;
public class InsertionSorter
{
  public void Sort(int [] list)
  {
      for(int i=1;i<list.Length;++i)
      {
          int t=list[i];
          int j=i;
          while((j>0)&&(list[j-1]>t))
          {
            list[j]=list[j-1];
            --j;
          }
        list[j]=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};
    InsertionSorter ii=new InsertionSorter();
    ii.Sort(iArrary);
    for(int m=0;m<=13;m++)
    Console.WriteLine("{0}",iArrary[m]);
      }
}
相关文章: