快速排序python实现
参考:挖坑填数+分治法
def quick_sort(l,left,right):
tail = left
head = right
pivot = l[left]
if left >= right:
return
while tail < head:
while tail < head and l[head] >= pivot:
head -= 1
if(tail < head):
l[tail] = l[head]
tail += 1
while tail < head and l[tail] < pivot:
tail += 1
if tail < head:
l[head] = l[tail]
head -= 1
l[head] = pivot
quick_sort(l,left,head - 1)
quick_sort(l,head + 1,right)
在线测试:牛客