nums = [5,4,3,2,1]
tt =0
for iin range(len(nums)-1):# 这个循环负责设置冒泡排序进行的次数
for jin range(len(nums)-i-1):# j为列表下标
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
tt = tt+1
print(tt)
print(nums)
nums = [5,4,3,2,1]
pp =0
for iin range(len(nums)):
for jin range(i+1,len(nums)):
if nums[i]>nums[j]:
nums[i],nums[j] = nums[j],nums[i]
print(nums)
pp = pp+1
print(pp)
网友评论