python的插入排序算法,代码如下:
def insert_sort(numbers):
length = len(numbers)
for i in range(1, length):
# 从第二个元素开始,每次取出一个元素,插入前面的序列使其有序
for j in range(0, i):
if numbers[j] > numbers[i]:
numbers[j], numbers[i] = numbers[i], numbers[j]
return numbers
if __name__ == "__main__":
numbers = [1, 55, 15, 3, 33, 4, 515, 22, 6]
numbers=insert_sort(numbers)
print(numbers)
代码不足请联系我哦