def bubble_sort(nums):
n = len(nums)
for i in range(n-1):
for j in range(n-i-1):
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
nums = [5, 3, 8, 2, 1]
print("排序前:", nums)
bubble_sort(nums)
print("排序后:", nums)
标签:sort,nums,冒泡排序,range,print,排序,bubble From: https://blog.51cto.com/u_16058927/6978280