冒泡排序:
a=[3,1,5,2,4] def bubbleSort(a): count=len(a) for i in range(0,count): for j in range(i+1,count): if a[i]>a[j]: a[i],a[j]=a[j],a[i] return a
a1=bubbleSort(a) print(a1)
插入排序:
a= [3, 4, 1, 2, 5] def insertSort(a): count = len(a) for i in range(1,count): key=a[i] j=i-1 while j>=0: if a[j]>key: a[j+1]=a[j] a[j]=key j-= 1 return a a1=insertSort(a) print(a1)