Python写冒泡排序的代码
时间: 2023-02-21 16:13:03 浏览: 24
用Python写冒泡排序代码
5星 · 资源好评率100%
答:下面是Python写的冒泡排序的代码:
def bubbleSort(nums):
n = len(nums)
# 遍历所有数组元素
for i in range(n):
# Last i elements are already in place
for j in range(0, n-i-1):
if nums[j] > nums[j+1] :
nums[j], nums[j+1] = nums[j+1], nums[j]
阅读全文