def q_sort(L,left,right):
if left < right:
index = pailie(L,left,right)
q_sort(L,left,index-1)
q_sort(L,index+1,right)
return L
def pailie(L,left,right):
value=L[left]
while left<right:
while left < right and L[right] >= value:
right-=1
L[left]=L[right]
while left < right and L[left] <= value:
left+=1
L[right]=L[left]
L[left]=value
return left
L = [5, 9, 1, 11, 6, 7, 2, 4]
print(q_sort(L,0,len(L)-1))
快速排序 python版本
最新推荐文章于 2021-07-18 15:37:19 发布