l1_1 = [122,32,10,76,12,11,90] def bubble_sort(lst): l1 = reversed(range(len(lst))) print(f'这里是l1{l1}') for j in l1: # 控制循环次数 for i in range(len(lst)-1): # 循环数列的索引 if lst[i] > lst[i+1]: lst[i],lst[i+1]=lst[i+1],lst[i] print(lst) bubble_sort(l1_1)
打印结果:
[10, 11, 12, 32, 76, 90, 122]