Commit 33b3d57a by BellCodeEditor

auto save

parent ce1e96e4
Showing with 0 additions and 18 deletions
alist = [114514, 114451, 114451, 141154, 115414, 115144, 154114, 114154]
a=len(alist)
for k in range(a-1):
for i in range(a-k-1):
if alist[i]>alist[i+1]:
alist[i],alist[i+1] = alist[i+1],alist[i]
print(alist)
#第一步:求出列表长度
#第二步:外层循环控制总共进行多少轮等于列表长度减一
#第三步:内层循环控制每一轮比较次数 第一轮长度减一 第二轮长度减二 第三轮长度减三......
#第四步:如果前面位置的值比后面位置的值大就交换位置(每次只能两两交换)
#第五步:从小到大排序
#alist[i],alist[i+1] = alist[i+1],alist[i]只能在python使用
#其他语言使用:
#t=alist[i]
#alist[i] = alist[i+1]
#alist[i+1] = t
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment