Python冒泡排序

# -*- coding: utf-8 -*-
# @Time     : 2018/11/16 16:35
# @Author   : Philly
# @Site     : 
# @File     : bubbleSort.py
# @Software : PyCharm Community Edition
def bubbleSort(nums):
    for i in range(len(nums)-1):    # 设置冒泡排序进行的次数
        for j in range(len(nums)-i-1):  # j为列表下标
            if nums[j] > nums[j+1]:
                nums[j], nums[j+1] = nums[j+1], nums[j]
    return nums

nums = [5, 23, 45, 6, 8, 2, 1]
print(bubbleSort(nums))
原文地址:https://www.cnblogs.com/liuliu3/p/9970245.html