[算法导论]插入排序 @ Python

class insertionsort():

    def insertion_sort(self,Array):
        for i in range(1, len(Array)):
            key = Array[i]
            j = i - 1
            while j >= 0 and Array[j] > key:
                Array[j+1] = Array[j]
                j -= 1
            Array[j+1] = key

        return Array

sort = insertionsort()

array = [1,3,5,7,9,2,4,6,8,10]

print sort.insertion_sort(array)

 

posted @ 2014-08-15 14:15  南郭子綦  阅读(432)  评论(0编辑  收藏  举报