冒泡排序……
while循环判断循环次数
list=[4165, 2315, 2165, 2123, 565, 89, 56, 56, 23, 6, 5, 1]
num=1
while num<len(list):
for i in range(len(list)-1):
if list[i]>list[i+1]:
list[i] ,list[i + 1]= list[i + 1],list[i]
num+=1
print(list)
for循环给出循环次数
list=[4165, 2315, 2165, 2123, 565, 89, 56, 56, 23, 6, 5, 1]
for i in range(len(list)-1):
for i in range(len(list)-1):
if list[i]>list[i+1]:
list[i] ,list[i + 1]= list[i + 1],list[i]
print(list)
来源:CSDN
作者:默金……
链接:https://blog.csdn.net/qq_42846555/article/details/104123251