EdisonChendi
4/14/2018 - 1:05 PM

insertion sort

insertion sort

#codint:UTF-8

def insertion_sort(l):
    if len(l) <= 1:
        return l
    for i in range(1, len(l)):
        key = l[i]
        for j in reversed(range(0, i)):
            c = l[j]
            if c > key:
                l[j], l[j+1] = key, l[j] # swap
            else:
                break

l = [7, 3, 8, 10, 11]
insertion_sort(l)
print(l)