#先自动生成一串随机数放置于列表中
import random
ls=[]
for i in range(10):
ls.append(random.randint(1,100))
#冒泡(均为降序)
for i in range(len(ls)-1):
for j in range(len(ls)-i-1):
if ls[j] ls[j],ls[j+1]=ls[j+1],ls[j] print(ls) #选择 for i in range(len(ls)-1): for j in range(i+1,len(ls)): if ls[i] ls[i],ls[j]=ls[j],ls[i] print(ls) #插入 for i in range(1,len(ls)): for j in range(0,i): if ls[j] ls[j],ls[i]=ls[i],ls[j] print(ls)