Python之插入排序

  • 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() 与深拷贝、浅拷贝

发布了135 篇原创文章 · 获赞 33 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_39541632/article/details/102993029