"""
直接插入排序:每次从未排序的序列中选择一个数,依次从尾开始和已排序的序列作对比,然后插入到适当的位置
"""
l = [2, 9, 10, 11, 3, 7, 4, 0, 6, 11, -7]
for i in range(1, len(l)):
temp = l[i]
j = i - 1
while j >= 0 and l[j] < temp:
l[j + 1] = l[j]
j -= 1
l[j + 1] = temp
print(l)
[11, 11, 10, 9, 7, 6, 4, 3, 2, 0, -7]