用python写一个冒泡排序
时间: 2023-03-10 09:16:18 浏览: 105
用Python写冒泡排序代码
5星 · 资源好评率100%
答案:下面是用Python写的冒泡排序程序:def bubbleSort(nums):
for i in range(len(nums)-1):
for j in range(len(nums)-i-1):
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
return nums
nums = [5,2,45,6,8,2,1]
print(bubbleSort(nums))
阅读全文