当前位置:首页 > Python教程 > python技巧

python 冒泡排序

def bubble_sort(blist):

    count = len(blist)

    for i in range(0, count):

        for j in range(i + 1, count):

            if blist[i] > blist[j]:

                blist[i], blist[j] = blist[j], blist[i]

    return blist

 

blist = bubble_sort([4,5,6,7,3,2,6,9,8])

print(blist)

原文:https://www.cnblogs.com/sea-stream/p/9689044.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐