python 冒泡法排序代码
def BubbleSort(lst): lst = list(lst) #copy collection to list for passesLeft in range(len(lst)-1, 0, -1): for i in range(passesLeft): if lst[i] < lst[i + 1]: lst[i], lst[i + 1] = lst[i + 1], lst[i] return lst
代码2
def BubbleSort2(lst): lst = list(lst) swapped = True while swapped: swapped = False for i in range(len(lst)-1): if lst[i] < lst[i+1]: lst[i], lst[i+1] = lst[i+1], lst[i] swapped = True return lst