插入排序

Insertion-sort-example-300px

 

            int temp = 0;
            for (int i = 1; i <= arr.Length-1; i++) 
            {
                temp = arr[i];
                int j = i - 1;
                for (; j >= 0; j-- )
                {
                    arr[j + 1] = arr[j];
                    if (temp >= arr[j])
                    {
                        break;
                    }
                }
                arr[j + 1] = temp;
            }

 

参考:

[1] 插入排序

     http://zh.wikipedia.org/wiki/%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F

[2] 排序算法

     http://zh.wikipedia.org/wiki/%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95

posted @ 2014-05-03 16:30  liqipeng  阅读(146)  评论(0编辑  收藏  举报