defquick_sort (array, left, right):ifLeft <Right:base_index=Division (array, left, right) Quick_sort (array, left, Base_index-1)#split again with less than the base valueQuick_sort (Array, Base_index + 1, right)#split again over the base valuedefDivision (array, left, right): Base_value=Array[right] I= Left forJinchRange (left, right):#traverse other elements except the last element ifARRAY[J] <= Base_value:#comparison with benchmark valuesArray[i], array[j] = Array[j], array[i]#is less than the base value, it is replaced before the listi + = 1#after the replacement, move backward, ready to accept the next replacementArray[i], array[right] = Array[right], array[i]#after the traversal is complete, place the base value after all values that are less than it returnI#returns the index of the base value for the split listif __name__=='__main__': A= [Random.randint (1, 1000) forIinchRange (50)] Quick_sort (A, 0, Len (a)-1) PrintA
Fast-sorting Python implementations