python实现排序算法
2021-06-16 16:03
标签:冒泡 col bre list nbsp 排序 插入排序 bubble pop 冒泡排序算法 python实现排序算法 标签:冒泡 col bre list nbsp 排序 插入排序 bubble pop 原文地址:https://www.cnblogs.com/gugubeng/p/9726577.html
def insert_sort(ilist):
for i in range(len(ilist)):
for j in range(i):
if ilist[i] ilist[j]:
ilist.insert(j,ilist.pop(i))
break
return ilist
ilist = insert_sort([2,3,4,5,6,4,33,2])
print(ilist)
插入排序算法
def bubble_sort(blist):
count = len(blist)
for i in range(0, count):
for j in range(i + 1, count):
if blist[i] > blist[j]:
blist[i], blist[j] = blist[j], blist[i]
return blist
blist = bubble_sort([4,5,6,7,3,2,6,9,8])
print (blist)