首页 > 代码库 > python冒泡排序

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=[3,123,34,43,0,3,6,8]

print(bubblesort(nums))

python冒泡排序