def sub_sort(arr,low,high): key=arr[low] while low<high: while low<high and arr[high]>=key: high-=1 arr[low]=arr[high] while low<high and arr[low]<=key: low+=1 arr[high]=arr[low] arr[low]=key return low def quick_sort(arr,low,high): if low<high: pivot=sub_sort(arr,low,high) quick_sort(arr, low, pivot-1) quick_sort(arr, pivot+1, high) # low = pivot + 1 # return arr if __name__=='__main__': arr=[8,7,6,0,8,9,12,45,78,23,45,67] print(arr) quick_sort(arr, 0, len(arr)-1) print(arr)
快排 Python实现
最新推荐文章于 2023-06-03 09:31:09 发布