Python3练习题 006 冒泡排序

import random

a = [random.randint(1,100) for i in range(10)]
def bu(target):
length = len(target)
while length > 0:
length -= 1
cur = 0
while cur < length: #拿到当前元素
if target[cur] < target[cur + 1]:
target[cur], target[cur + 1] = target[cur + 1], target[cur]
cur += 1
return target


print (bu(a))
posted @ 2018-06-02 14:51  点点花飞谢  阅读(557)  评论(0编辑  收藏  举报