python快速排序
2020-12-13 14:50
标签:name 排序 def and code pytho test col += python快速排序 标签:name 排序 def and code pytho test col += 原文地址:https://www.cnblogs.com/qiaokuahai/p/11569731.html# coding=utf-8
def quick_sort(arr, start, end):
if start >= end:
return
left = start
right = end
pivotkey = arr[start]
while left right:
while left and arr[right] >= pivotkey:
right -= 1
arr[left] = arr[right]
while left and arr[left] pivotkey:
left += 1
arr[right] = arr[left]
arr[left] = pivotkey
quick_sort(arr, start, left-1)
quick_sort(arr, right + 1, end)
if __name__ == "__main__":
test_list = [2, 10, 11, 6, 19, 21]
quick_sort(test_list, 0, len(test_list)-1)
print(test_list)