python 冒泡排序
2021-05-01 19:26
标签:nbsp ESS 一个 col with turn 冒泡 exit span 冒泡排序 运行结果: python 冒泡排序 标签:nbsp ESS 一个 col with turn 冒泡 exit span 原文地址:https://www.cnblogs.com/bashliuhe/p/13205984.htmldef maopaoSort(array):
#一共需要n次的循环,每一个都要找到没有拍好序的最大值
for i in range(len(array)):
#将没有排好序的数组找最大值
for j in range(len(array)-i-1):
if array[j]>array[j+1]:
array[j],array[j+1]=array[j+1],array[j]
return array
if __name__==‘__main__‘:
array=[9,8,10,15,7,3,20,14,2]
maopaoSort(array)
print(array)
[2, 3, 7, 8, 9, 10, 14, 15, 20]
Process finished with exit code 0
上一篇:初识Windows程序