当前位置: 代码迷 >> 综合 >> python编程---example12
  详细解决方案

python编程---example12

热度:74   发布时间:2023-10-18 11:35:06.0

快速排序算法。 

def quick_sort(arr,start=0,end=None):if end is None:end = len(arr) - 1if end <= start:return(arr)i,j = start,endref = arr[start]while j>i:if arr[j]>=ref:j = j - 1else:arr[i],arr[j],arr[i+1] = arr[j],arr[i+1],arr[i]i = i + 1quick_sort(arr,start=start,end=i-1)quick_sort(arr,start=i+1,end=end)return(arr)print(quick_sort([2,4,1,6,3,1,9,5,8,3,0,1,7]))

 

  相关解决方案