zoukankan      html  css  js  c++  java
  • [原创]直接插入排序InsertSort Virus

     class InsertSort
        {
            private int[] mylist;

            public InsertSort()
            {
                mylist = new int[] {  19, 13, 5, 27, 1, 26, 31, 16, 2, 9, 11, 21 } ;
            }

            public void Start()
            {
                int T;
                for (int j =1; j < mylist.Length; j++)
                {
                    T = mylist[j];
                    int i = j - 1;
                    while (i>=0 && mylist[i]>T)
                    {
                        mylist[i+1]=mylist[i];
                        i=i-1;
                    }
                    mylist[i + 1] = T;
                }
            }

            public void Display()
            {
                for (int i = 0; i < mylist.Length - 1; i++)
                {
                    Console.WriteLine(mylist[i].ToString());
                }
            }
        }
    class Program
        {
            static void Main(string[] args)
            {
                InsertSort insert = new InsertSort();
                insert.Start();
                insert.Display();
                Console.ReadLine();
            }
        }

    【Blog】http://virusswb.cnblogs.com/

    【MSN】jorden008@hotmail.com

    【说明】转载请标明出处,谢谢

    反馈文章质量,你可以通过快速通道评论:

  • 相关阅读:
    349. 两个数组的交集
    383. 赎金信
    242. 有效的字母异位词
    844. 比较含退格的字符串
    904. 水果成篮
    剑指offer(9)变态跳台阶
    剑指offer(8)跳台阶
    剑指offer(7)斐波那契数列
    剑指offer(6)旋转数组的最小数字
    剑指offer(5)用两个栈实现队列
  • 原文地址:https://www.cnblogs.com/virusswb/p/852523.html
Copyright © 2011-2022 走看看