Problem Solving Ideas:
Cases:
Program:
Import TimeImportRandomdefCal_time (func):#adorner, used to detect the time the algorithm executes defWrapper (*args,**Kwargs): T1=time.time () result=func (*args,**Kwargs) T2=time.time ()Print("%s Running time:%s secs."% (func.__name__, t2-t1)) returnresultreturnWrapper@cal_timedefCount_sort (li,max_num): Count= [0 forIinchRange (Max_num + 1)]#from 0 ~ max_num forNuminchLi#Traverse LiCount[num] + = 1#if the number of Li appears once, then increase the number of indexes by 1i =0 forNum,minchEnumerate (count):#Enumerate: Index + value num is the number of index number M forJinchRange (m): Li[i]=num I+ = 1Data= [] forIinchRange (100000): Data.append (random.randint (0,100))#both before and after Randint includeCount_sort (data,100)Print(data)
The running result of the program is:
``````````````
Count Sort----Giveaway 1