正文
博客地址:https://www.cnblogs.com/zylyehuo/
def partition(li, left, right):
tmp = li[left]
while left < right:
while left < right and li[right] >= tmp:
right -= 1
li[left] = li[right]
print(li, 'right')
while left < right and li[left] <= tmp:
left += 1
li[right] = li[left]
print(li, 'left')
li[left] = tmp
return left
def _quick_sort(li, left, right):
if left < right:
mid = partition(li, left, right)
_quick_sort(li, left, mid - 1)
_quick_sort(li, mid + 1, right)
def quick_sort(li):
_quick_sort(li, 0, len(li) - 1)
ls = [5, 7, 9, 4, 8, 3, 6, 1]
quick_sort(ls)
print(ls)
复制