冒泡算法

排序

def bubbleSort(arr):
    length = len(arr)
    for j in range(length-1,0,-1):
        for i in range(j):
            if arr[i] > arr[i+1]:
                arr[i],arr[i+1] = arr[i+1],arr[i]
    return arr
ret = bubbleSort([23,34,56,78,23,45,67,90,78,54])
print(ret)

你可能感兴趣的:(冒泡算法)