冒泡排序(LOW)

博客地址:https://www.cnblogs.com/zylyehuo/

# _*_coding:utf-8_*_

import random

def bubble_sort(li):
    for i in range(len(li)-1):
        exchange = False
        for j in range(len(li)-i-1):
            if li[j] > li[j+1]:
                li[j], li[j+1] = li[j+1], li[j]
                exchange = True
        if not exchange:
            return


li = list(range(100))
random.shuffle(li)
print(li)
bubble_sort(li)
print(li)

posted @ 2023-08-12 17:02  zylyehuo  阅读(6)  评论(0编辑  收藏  举报