class Solution: def insertion_sort(lst): for i in range(1, len(lst)): for j in range(i, 0, -1): if lst[j] < lst[j - 1]: lst[j], lst[j - 1] = lst[j - 1], lst[j] else: break # 示例用法 solve = Solution() my_list = [8, 3, 1, 5, 2] solve.insertion_sort(my_list) print(my_list)
标签:sort,插入排序,list,Solution,lst,my From: https://www.cnblogs.com/Crown-V/p/17739324.html