当前位置 : 主页 > 编程语言 > python >

Python之插入排序

来源:互联网 收集:自由互联 发布时间:2022-06-24
import random import copy def insertSort ( num ): """ 插入排序 :param num: :return: """ sortL = [] print ( num ) for i in range ( 1 , len ( num )): key = num [ i ] j = i - 1 while j = 0 and key num [ j ]: num [ j + 1 ] = num [ j ] j -=
import random
import copy
def insertSort(num):
"""
插入排序
:param num:
:return:
"""
sortL = []
print(num)
for i in range(1, len(num)):
key = num[i]
j = i - 1
while j >= 0 and key < num[j]:
num[j + 1] = num[j]
j -= 1
num[j + 1] = key
sortL.append(copy.deepcopy(num))
# for i in sortL:
# print(i)
  • ​​Python append() 与深拷贝、浅拷贝​​


上一篇:Python小记——repr和字符串
下一篇:没有了
网友评论