py冒泡排序

python 版本冒泡排序

def bubble_sort(list):
unsorted_until_index = len(list) - 1
sorted = False

while not sorted:
    sorted = True
    for i in range(unsorted_until_index):
        if list[i] > list[i+1]:
            sorted = False
            list[i], list[i+1] = list[i+1], list[i]
    unsorted_until_index = unsorted_until_index - 1

list = [65, 55, 45, 35, 25, 15, 10]
bubble_sort(list)
print list

猜你喜欢

转载自blog.csdn.net/weixin_33890526/article/details/90938896