排序算法

时间复杂度0(n^2)

# encoding: utf-8
import  random
#插入排序
def insertionSort(arr):
        for index in range(1,len(A)):
        key = A[index]
        jndex = index -1
        while jndex >=0 and A[jndex] > key:
            A[jndex+1] = A[jndex]
            jndex = jndex - 1
        A[jndex+1] = key


arr = []
for i in range(0,10,1):
    arr.append(random.randint(0, 10000))
print arr
print insertionSort(arr)

你可能感兴趣的:(算法导论)