def bubble_sort(alist): """冒泡排序""" n = len(alist) for j in range(n-1): count = 0 for i in range(0, n-1-j): #第一个元素从头走到位 if alist[i] > alist[i+1]: alist[i],alist[i+1] = alist[i+1], alist[i] if 0 == count: return alist if __name__ == "__main__": li = [54, 26, 93, 17, 77, 31, 44, 55, 20] print(li) bubble_sort(li) print(li)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)