Python 实现冒泡
nums = [3,1,2]
n=len(nums)
for i in range(n-1):
for j in range(n-i-1):
if nums[j]>nums[j+1]:
nums[j+1],nums[j]=nums[j],nums[j+1]
print(nums)
[1, 2, 3]
nums = [3,1,2]
n=len(nums)
for i in range(n-1):
for j in range(n-i-1):
if nums[j]>nums[j+1]:
nums[j+1],nums[j]=nums[j],nums[j+1]
print(nums)
[1, 2, 3]