关于基础排序算法的思考--插入排序

插入排序方法

            int[] a = { 3, 1, 5, 7, 2, 4, 9, 6 };

            for (int i = 1; i < 8; i++)
            {
                if (a[i]<a[i-1])
                {
                    int x = a[i];
                    int j;
                    for (j = i - 1; j>=0 && a[j] >x; j--)
                    {
                        a[j + 1] = a[j];
                    }
                    a[j+1] = x;
                }
            }


            for (int j = 0; j < 8; j++)
            {
                Console.WriteLine(a[j] + ",");
            }

  

原文地址:https://www.cnblogs.com/livexiaojie/p/6703068.html