__author__ = ' student ' Quicksortstep 1, choose one pivot, such as Pivot=la[0]step 2, scan the data from right side, find Data less than pivot, then swap this with Pivotpivot=1 [4] 5 7 3 9 [J]then scan from left side, find data greater tha n Pivot, then swap the position J and I4 [] 7 3 9 5when i>=j then finish one loop. Then put the pivot in the I; All data is dived by pivot now. than pivot and right is greater than Pivot.think, step by step, do it and try Somethingstep 3. Then you have the parts to sort, the left part and the right part.recursive call the This method to sort ' import randomdef quicksort (la,l,r): If L>=r:return left=l;right=r Pivot=la[left] while left < Right:while left< La[right]>pivot:right-=1 if Left<right:la[left]=la[right] left +=1 while Left<right and la[left]<pivot:left+=1 if left<right:la[right]=la[ Left La[left]=pivot quicksort (la,l,left-1) quicksort (LA,LEFT+1,R) def quicksort2 (LA): If Len (LA) <=1:retu RN La return quicksort2 ([LT for Lt in La[1:] if lt<la[0]]) + LA[0:1]+QUICKSORT2 ([ge for GE in la[1:] if ge>=la[0]] ) Import Syssys.setrecursionlimit (999) la=[]def generatenumbers (La,len): For x in range (len): La.extend ([Random.ra Ndint (1,50)]) generatenumbers (la,1000) Print Laquicksort (La,0,len (LA)-1) Print LA
Python Quicksort demo