def partition(arr, low, high):
i = low - 1
pivot = arr[high]
for j in range(low, high):
if arr[j] <= pivot:
i = i+1
arr[i],arr[j] = arr[j],arr[i]
arr[i+1],arr[high] = arr[high],arr[i+1]# ???
return i+1
def quick_sort(arr, low, high):
if low < high:
pi = partition(arr,low,high)
quick_sort(arr, low, pi-1)
quick_sort(arr, pi+1, high)
arr = [3,2,9,34,5,3,9,7,0,1]
quick_sort(arr, 0, len(arr)-1)
print(arr)
快速排序Python
最新推荐文章于 2024-04-26 16:26:48 发布