python基础之冒泡排序

list_pratisce = [45,69,8,19,9]
n = len(list_pratisce)
for j in range(n):
    for i in range(n-1):
        if list_pratisce[i] > list_pratisce[i+1]:
            temp = list_pratisce[i]
            list_pratisce[i] = list_pratisce[i+1]
            list_pratisce[i+1] = temp
print(list_pratisce)
输出结果:
[8, 9, 19, 45, 69]

本文标题:python基础之冒泡排序
网站链接:http://www.hxwzsj.com/article/pdggso.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 外贸营销网站建设 成都网站建设 高端网站设计 教育网站设计方案 重庆网站制作 成都网站制作 成都商城网站制作 成都网站设计 高端网站设计 成都网站建设公司 成都网站建设公司 成都网站设计 成都定制网站建设 网站建设公司 营销网站建设 成都网站制作 专业网站设计 成都网站建设 成都网站建设 成都模版网站建设 阿坝网站设计 手机网站制作设计