冒泡
python
def boll(lis):
i = 0
while i<len(lis)-1:
j = 0
while j<len(lis)-1-i:
if lis[j] > lis[j+1]:
lis[j],lis[j + 1] = lis[j+1],lis[j]
j+=1
i+=1
选择排序
python
def selct1(lit):
i = 0
while i<len(lit)-1:
j =i+1
min1 = i
while j < len(lit):
if lit[j] < lit[min1]:
min1 = j
j += 1
lit[i],lit[min1] = lit[min1],lit[i]
i+=1
插入
python
def insert(lit):
i = 1
for i in range(1,len(lit)):
j = i-1#手牌下标
tmp = lit[i] #抓牌下标
while j>=0 and lit[j]>tmp:
lit[j+1] = lit[j]
j-=1
lit[j+1] = tmp