python-冒泡排序算法
def maopao(list):
len_list = len(list)
for i in range(len_list - 1, 0, -1):
count = 0
for j in range(i):
if list[j] > list[j + 1]:
list[j + 1], list[j] = list[j], list[j + 1]
count += 1
if 0 == count:
break
return list
def maopao2(list):
len_list = len(list)
for i in range(len_list):
for j in range(0, len_list - i - 1):
if list[j] > list[j + 1]:
list[j + 1], list[j] = list[j], list[j + 1]
return list
posted on 2021-05-15 21:05 ClarenceSun 阅读(45) 评论(0) 编辑 收藏 举报