nums = [1,9,8,5] print(nums) print("=========") length = len(nums) for i in range(length-1): maxindex = i for j in range(i+1,length): if nums[j] > nums[maxindex]: maxindex = j if i == maxindex: continue nums[i],nums[maxindex] = nums[maxindex],nums[i] print(nums) print("=========") print(nums)
原文:https://www.cnblogs.com/alrenn/p/12658705.html