您的位置:首页 > 产品设计 > UI/UE

快速排序 QuickSort

2015-08-11 17:02 417 查看
def adjustArry(arry,left,right):
i = left
j = right
x = arry[i]

while i < j:
while i<j and arry[j] >= x:
j-=1
if arry[j] < x:
arry[i] = arry[j]
i+=1
while i<j and arry[i] <= x:
i+=1
if arry[i] > x:
arry[j] = arry[i]
j-=1
arry[i] = x

return i

def quickSort(arry,left,right):
if left < right:
i = adjustArry(arry,left,right)
quickSort(arry,left,i-1)
quickSort(arry,i+1,right)

return arry

if __name__=='__main__':
arry = [72,6,57,88,60,42,83,73,48,85]
print quickSort(arry,0,len(arry)-1)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: