Fix sorts/radix_sort (#338)

This commit is contained in:
Inno Fang 2019-02-09 10:14:23 +08:00 committed by Ashwek Swamy
parent faf16d7ced
commit 17a6d1c1a7

View File

@ -1,10 +1,11 @@
def radixsort(lst): def radixsort(lst):
RADIX = 10 RADIX = 10
maxLength = False placement = 1
tmp , placement = -1, 1
while not maxLength: # get the maximum number
maxLength = True max_digit = max(lst)
while placement < max_digit:
# declare and initialize buckets # declare and initialize buckets
buckets = [list() for _ in range( RADIX )] buckets = [list() for _ in range( RADIX )]
@ -13,9 +14,6 @@ def radixsort(lst):
tmp = int((i / placement) % RADIX) tmp = int((i / placement) % RADIX)
buckets[tmp].append(i) buckets[tmp].append(i)
if maxLength and tmp > 0:
maxLength = False
# empty lists into lst array # empty lists into lst array
a = 0 a = 0
for b in range( RADIX ): for b in range( RADIX ):