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
+ '''
2
2
# Create by LokiSharp(loki.sharp#gmail) at 2017-1-22
3
3
'''
4
4
@@ -176,6 +176,34 @@ def countingSort(arr, maxValue=None):
176
176
bucket[j] -= 1
177
177
return arr
178
178
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
+
179
207
180
208
if __name__ == '__main__':
181
209
sortTest(bubbleSort, TOTAL)
@@ -185,3 +213,4 @@ def countingSort(arr, maxValue=None):
185
213
sortTest(mergeSort, TOTAL)
186
214
sortTest(quickSort, TOTAL)
187
215
sortTest(heapSort, TOTAL)
216
+ sortTest(radixSort, TOTAL)
You can’t perform that action at this time.
0 commit comments