今天更新一下用Python学习数据结构与算法篇之 冒泡法
未经允许不可转载!
def bubble_sort(lis=[]):
se_len = len(lis)
j = se_len - 1
while j > 0:
i = 0
flag = 0
while i < j:
if lis[i] > lis[i+1]:
lis[i], lis[i+1] = lis[i+1], lis[i]
flag = 1
i += 1
print(lis)
if flag == 0:
break
else:
j = j - 1
a = [4, 3, 2, 1]
bubble_sort(a)
print(a)