# author: Jingke
def bubble_sort(nums):
n = 1
for i in range(len(nums) - 1):
print('i:%s'%i)
for j in range(len(nums) - 1 - i): #第i次时,有i个已经排好,剩余需要对比大小第个数
if nums[j] > nums[j + 1]:
nums[j], nums[j + 1] = nums[j + 1], nums[j]
print(nums)
return nums
list = [6, 4, 8, 3, 7, 5]
bubble_sort(list)
网友评论