Merge pull request #135 from KuLi/radix_sort-fix

#130 fixed radix sort for python 3
This commit is contained in:
Harshil 2017-10-17 18:50:05 +05:30 committed by GitHub
commit 54eb79f53a

View File

@ -2,19 +2,19 @@ def radixsort(lst):
RADIX = 10 RADIX = 10
maxLength = False maxLength = False
tmp , placement = -1, 1 tmp , placement = -1, 1
while not maxLength: while not maxLength:
maxLength = True maxLength = True
# declare and initialize buckets # declare and initialize buckets
buckets = [list() for _ in range( RADIX )] buckets = [list() for _ in range( RADIX )]
# split lst between lists # split lst between lists
for i in lst: for i in lst:
tmp = i / placement tmp = i // placement
buckets[tmp % RADIX].append( i ) buckets[tmp % RADIX].append( i )
if maxLength and tmp > 0: if maxLength and tmp > 0:
maxLength = False 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 ):
@ -22,6 +22,6 @@ def radixsort(lst):
for i in buck: for i in buck:
lst[a] = i lst[a] = i
a += 1 a += 1
# move to next # move to next
placement *= RADIX placement *= RADIX