- using System;
- namespace suanfa
- {
- /// <summary>
- /// InsertionSorter :插入排序算法。
- /// </summary>
- public class InsertionSorter
- {
- public InsertionSorter()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- 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 MainClassInsertion
- {
- public static void MainInsertion()
- {
- int[] iArrary=new int[]{1,13,3,6,10,55,99,2,87,12,34,75,33,47};
- InsertionSorter ii=new InsertionSorter();
- ii.Sort(iArrary);
- Console.WriteLine("插入算法排序:");
- for(int m=0;m<iArrary.Length;m++)
- Console.Write("{0} ",iArrary[m]);
- Console.WriteLine();
- Console.WriteLine();
- }
- }
- }