插入排序


a = [4, 6, 2, 1, 8, 3]

for i in xrange(len(a)):
    for j in xrange(i):
        if a[i] < a[j]:
            tmp = a[j]
            a[j] = a[i]
            a[i] = tmp

print a  # [1, 2, 3, 4, 6, 8]

你可能感兴趣的:(插入排序)