def bubbleSort(nums): i = len(nums) - 1 while (i > 0): last_index = 0 for j in range(i): if nums[j] > nums[j+1]: nums[j],nums[j+1] = nums[j+1],nums[j] last_index = j i = last_index return nums
时间: 2024-10-13 15:40:21
def bubbleSort(nums): i = len(nums) - 1 while (i > 0): last_index = 0 for j in range(i): if nums[j] > nums[j+1]: nums[j],nums[j+1] = nums[j+1],nums[j] last_index = j i = last_index return nums