python学习之冒泡
#冒泡排序
#嵌套循环,后一个和前一个比较,小的放前面
a = [1,3,6,2,4,9,7,8]
for j in range(len(a)-1):
# print(aa)
for i in range(len(a)-1-j):
if a[i]> a[i+1]:
a[i],a[i+1]= a[i+1],a[i]
print(a)
#递归冒泡
a = [1,3,6,2,4,9,7,8]
count = len(a)
def maop(a,count):
for i in range(count-1):
if a[i]>a[i+1]:
a[i],a[i+1] = a[i+1],a[i]
maop(a,count-1)
return a
print(maop(a,count))