首页 > 代码库 > 插入排序之python实现源码

插入排序之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 caseold = [2, 5, 3, 0, 2, 3, 0, 3]insert_sort(old)print old

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

插入排序之python实现源码