欢迎访问我的博客 https://javascript.shop

排序 普通插入法排序

原文发布时间为: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;
            }

        }

    }
}

posted @ 2017-07-12 00:05  孑孓子  阅读(101)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop