python实现快速排序

"""快速排序"""
def quicksort(lista):
if len(lista) < 2:
return lista
else:
middle = lista[0]
less = [x for x in lista[1:] if x <= middle]
more = [x for x in lista[1:] if x > middle]
return quicksort(less)+[middle]+quicksort(more)
listb = [6,23,6,7,10,2,54,5]
print(quicksort(listb))

没有更多推荐了,返回首页