1. 程式人生 > >使用直接排序法對一維數組進行排序

使用直接排序法對一維數組進行排序

highlight 維數 csharp ray pre 使用 str urn nbsp

實現效果:

  技術分享圖片

實現原理:

  技術分享圖片

實現代碼:

        public int[] sory(int[] intArray)
        {
            for (int i = 0; i < intArray.Length;i++ )
            {
                int j = i;
                int temp = intArray[i];
                while((j>0)&&temp>(intArray[j-1])){
                    intArray[j] = intArray[j - 1];
                    j--;
                }
                intArray[j] = temp;
            }
            return intArray;
        }

  

使用直接排序法對一維數組進行排序