1. Principle:
2. Code implementation
defQuick_sort (alist, Start, end):"""Quick Sort""" #Recursive exit conditions ifStart >=End:return #sets the starting element as the datum element to find the positionMID =Alist[start]#Low is the left-to-right cursor for the left of the sequenceLow =Start#High is the right-to-left cursor to the right of the sequenceHigh =End whileLow <High :#If low is not coincident with high, the element with high points is not smaller than the datum element, then high moves to the left whileLow < High andAlist[high] >=Mid:high-= 1#Place the high- pointing element in the low positionAlist[low] =Alist[high]#If low is not coincident with high, the element that is pointed to is smaller than the datum element, and the lower is moved to the right whileLow < High andAlist[low] <Mid:low+ = 1#Place the element with low pointing to the high positionAlist[high] =Alist[low]#after exiting the loop, low is coincident with high, at which point the position is the correct position of the datum element #Place a datum element at that locationAlist[low] =Mid#Quick ordering of sub-sequences to the left of a datum elementQuick_sort (alist, start, low-1) #Quick ordering of sub-sequences to the right of a datum elementQuick_sort (Alist, low+1, end) Alist= [54,26,93,17,77,31,44,55,20]quick_sort (Alist,0,len (alist)-1)Print(alist)
Python data structures and algorithms 12th Day "Quick Sort"