Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 75a861b

Browse files
nchhabra1311hustcc
authored andcommitted
Added radix sort in pythonSortTest.py (hustcc#37)
* Added radix sort in pythonSortTest.py * Improved code readability as suggested
1 parent 00f39c7 commit 75a861b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

‎src/pythonSortTest.py‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

180208
if __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)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /