Fast sorting algorithm
Quick Line Idea:
Take an element p (the first element) so that the element P is returned to the position;
The list is divided by P into two parts, the left side is smaller than p, the right side is larger than p;
Recursion completes the sort.
The complexity of time is:
O (NLOGN)
ImportRandomImport TimedefCal_time (func):"""test time Adorner:p Aram Func: Receives a function: return:""" defWrapper (*args, * *Kwargs): Ti=time.time () x= Func (*args, * *Kwargs) Ti2=time.time ()Print("Time Cost :", Func.__name__, Ti2-ti)returnxreturnwrapperdefquick_sort_x (data, left, right):ifLeft <Right :#Place the number in the left position, return the digitMID =partition (data, left, right)#Recursive OperationQuick_sort_x (data, left, mid-1) quick_sort_x (data, mid+ 1, right)defpartition (data, left, right):"""To implement a bitwise operation:P Aram data: Unordered list:p Aram Left: List the subscript:p Aram Right:len (data)-1:return: Sorted list"""tmp=Data[left] whileLeft <Right : whileLeft < Right andData[right] >=Tmp:right-= 1Data[left]=Data[right] whileLeft < Right andData[left] <=Tmp:left+ = 1Data[right]=Data[left] Data[left]=tmpreturnRight@cal_timedefquick_sort (data):returnquick_sort_x (data, 0, Len (data)-1) da= List (Range (10000) ) random.shuffle (DA) quick_sort (DA)Print(DA)
Fast sorting algorithm