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]
posted @ 2018-06-26 13:42  luoganttcc  阅读(76)  评论(0编辑  收藏  举报