插入排序之python实现源码

def insert_sort(old):
for i in range(1, len(old)):
for j in range(i, 0, -1):
if(old[j] < old[j-1]):
tmp = old[j]
old[j] = old[j-1]
old[j-1] = tmp # test case
old = [2, 5, 3, 0, 2, 3, 0, 3]
insert_sort(old)
print old

插入排序的时间复杂度O(N^2)

上一篇:web优化规范


下一篇:cookie跟session自我介绍