Here's how the introduction to Algorithms is divided:
ImportRandomdefpartition (array, left, right): Pivot=Array[left] I= Left#J left +1 -right forJinchRange (left + 1, right + 1): ifARRAY[J] <pivot:i+ = 1Temp=Array[i] Array[i]=Array[j] Array[j]=Temp Temp=Array[left] Array[left]=Array[i] Array[i]=TempreturnIdefquickSort (array, left, right):ifLeft <Right:pos=partition (array, left, right) QuickSort (array, left, POS-1) QuickSort (array, pos+1, right)if __name__=='__main__': Arr= [] forIinchRange (40): Arr.append (Random.randrange (10,100)) Printarr quickSort (arr, 0, Len (arr)-1) PrintArr
The style of the code here still focuses on the C language.
The result of the operation is:
~/documents/py python 5. py[44, 46, 89, 97, 89, 68, 36, 28, 43, 74, 19, 62, 62, 53, 30, 30, 32, 98, 62, 25, 63, 37 , 94, (+), 19, 21, 24, 25, 28, 30, 30, 32, 36, 37,,, +, +, (+), (+), (+),. 43, 44, 46, 46, 48, 49, 53, 53, 57, 62, 62, 62, 62, 63, 63, 67, 68, 74, 75, 75, 76, 80, 89, 89, 90, 93, 94
Python for quick sorting