File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 1- '''
1+ '''
22# Create by LokiSharp(loki.sharp#gmail) at 2017-1-22
33'''
44
@@ -176,6 +176,34 @@ def countingSort(arr, maxValue=None):
176176 bucket [j ] -= 1
177177 return arr
178178
179+ def radix_count (exp1 ):
180+ global list
181+ n = len (list )
182+ output = [0 ] * (n )
183+ count = [0 ] * (10 )
184+ for i in range (0 , n ):
185+ index = (list [i ] / exp1 )
186+ count [(index ) % 10 ] += 1
187+ for i in range (1 ,10 ):
188+ count [i ] += count [i - 1 ]
189+ i = n - 1
190+ while i >= 0 :
191+ index = (list [i ]/ exp1 )
192+ output [count [(index ) % 10 ] - 1 ] = list [i ]
193+ count [(index ) % 10 ] -= 1
194+ i -= 1
195+ i = 0
196+ for i in range (0 ,len (list )):
197+ list [i ] = output [i ]
198+
199+ def radixSort ():
200+ global list
201+ max1 = max (list )
202+ exp = 1
203+ while max1 / exp > 0 :
204+ radix_count (exp )
205+ exp *= 10
206+
179207
180208if __name__ == '__main__' :
181209 sortTest (bubbleSort , TOTAL )
@@ -185,3 +213,4 @@ def countingSort(arr, maxValue=None):
185213 sortTest (mergeSort , TOTAL )
186214 sortTest (quickSort , TOTAL )
187215 sortTest (heapSort , TOTAL )
216+ sortTest (radixSort , TOTAL )
You can’t perform that action at this time.
0 commit comments