# A:list,p:start point,r:end point# how to use:calling "quick_sort(A,0,len(A)-1)"def quick_sort(A,p,r):if p<r:q=partition(A,p,r)quick_sort(A,p,q)quick_sort(A,q+1,r)# partition devides list(over pivot and under pivot)# return: number of under pivot pointdef partition(A,p,r):pivot=A[r]i=p-1for j in range(p,r):if A[j]<=pivot:i+=1A[i],A[j]=A[j],A[i]A[i+1],A[r]=A[r],A[i+1]return i
使い方はquick_sort(A,0,len(A)-1)をよべばOK
0 件のコメント:
コメントを投稿