nums = [6, 11, 7 ,9, 4, 2,1]
i = len(nums) - 1
j = 1
while j < i:
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
j += 1
print(nums)
lst = sorted(nums)
print(lst)
lst = sorted(nums, reverse=True)
print(lst)
结果:
[6, 7, 9, 4, 2, 1, 11]
[1, 2, 4, 6, 7, 9, 11]
[11, 9, 7, 6, 4, 2, 1]
本文出自 “净空蓝星” 博客,请务必保留此出处http://jingkonglanxing.blog.51cto.com/1152128/1910308
原文地址:http://jingkonglanxing.blog.51cto.com/1152128/1910308