首页 > 代码库 > 排序 普通插入法排序

排序 普通插入法排序

原文发布时间为:2009-03-06 —— 来源于本人的百度文章 [由搬家工具导入]

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

namespace sorts
{
    public class Class2//插入法排序
    {
        public static void Main()
        {
            int[] iArrary = new int[] { 1, 5, 3, 6, 10, 3, 9 };
            Sort(iArrary);
            for (int m = 0; m < iArrary.Length; m++)
                Console.Write("{0} ", iArrary[m]);
            Console.ReadLine();
        }
        public static 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;
            }

        }

    }
}

排序 普通插入法排序