。。。
1 def insertSort(nums): 2 length = len(nums) 3 for i in range(1,length): 4 x = nums[i] 5 for j in range(i,-1,-1): 6 if x < nums[j-1]: 7 nums[j] = nums[j-1] 8 else: 9 break 10 nums[j] = x 11 return nums
。。。
1 def insertSort(nums): 2 length = len(nums) 3 for i in range(1,length): 4 x = nums[i] 5 for j in range(i,-1,-1): 6 if x < nums[j-1]: 7 nums[j] = nums[j-1] 8 else: 9 break 10 nums[j] = x 11 return nums