上代码
#!c:/python33/python def bubble_sort(arr): flag = True for i in range(len(arr)-1): if not flag: break flag = False for j in range(i, len(arr)): if (arr[i]>arr[j]): arr[i], arr[j] = arr[j], arr[i] flag = True return arr; arr = list(range(20, 0, -1)) print(arr) print(bubble_sort(arr))