using System;
using System.Collections.Generic;
using System.Text;

namespace SortAlgorithms
{
    class InsertionSorter
    {
        public void Sort(int[] arr)
        {
            for (int i = 1; i < arr.Length; i++)
            {
                int t = arr[i];
                int j = i;
                while ((j > 0) && (arr[j - 1] > t))
                {
                    arr[j] = arr[j - 1];
                    --j;
                }
                arr[j] = t;
            }
        }
        //static void Main(string[] args)
        //{
        //    int[] arry = new int[] { 1,5,3,6,3,8};
        //    InsertionSorter i = new InsertionSorter();
        //    i.Sort(arry);
        //    foreach (int m in arry)
        //    {
        //        Console.WriteLine(m);
        //    }
        //    Console.ReadLine();

        //}
    }
}

posted on 2009-04-27 20:41  WQL.NET  阅读(91)  评论(0编辑  收藏  举报