插入排序 @ Python
# _*_ coding: utf-8 _*_
import random as rd
def insertion_sort(A):
'''
:param A: list of number
:return: list of number
从小到大排序
'''
size = len(A)
i = 1
while i < size:
k = A[i] #key 值
j = i - 1
while j >= 0:
if k < A[j]:
A[j + 1] = A[j]
j -= 1
else:
A[j + 1] = k #找到确切位置
break
i += 1
return A
A = []
for i in range(10000):
A.append(rd.randint(1, 10000))
print insertion_sort(A)