快排----Python模板
2021-06-09 09:04
标签:quicksort style turn enter return int partition quick i+1 快排----Python模板 标签:quicksort style turn enter return int partition quick i+1 原文地址:https://www.cnblogs.com/z-712/p/14494692.htmlquickSort
def partition(arr,low, high):
i=(low-1)
p=arr[high]
for j in range(low, high):
if arr[j]p:
i+=1
arr[i],arr[j]=arr[j],arr[i]
arr[i+1],arr[high]=arr[high],arr[i+1]
return i+1
def quicksort(arr,low,high):
if lowhigh:
base=partition(arr,low,high)
quicksort(arr,low,base-1)
quicksort(arr,base+1,high)
arr=[10,203,20,22,11,100]
n=len(arr)
quicksort(arr,0,n-1)
print(‘ ‘.join(map(str, arr)))