实现源码
def bubble(array): flag = len(array)-1 while flag >0: iter = 0 for i in range(flag): if array[i] > array[i+1]: array[i], array[i+1]= array[i+1],array[i] iter=i flag = iter array = [5,3,18,99,8,2,8] if __name__ == "__main__": bubble(array) print array
时间: 2024-11-10 04:24:01