请帮我写一下Python冒泡排序的程序
时间: 2023-02-23 11:09:37 浏览: 73
python冒泡排序程序
def bubble_sort(nums):
# 冒泡排序
for i in range(len(nums)-1):
for j in range(len(nums)-1-i):
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
return nums
nums = [5,3,8,7,2,9]
print(bubble_sort(nums))
阅读全文