def maopao(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 = [1, 2, 7, 3, 9, 8, 5]
print(maopao(nums))
转载于:https://www.cnblogs.com/dlmltao/p/9998685.html