2017-02-25 23:06:58 +08:00
|
|
|
def radixsort(lst):
|
|
|
|
RADIX = 10
|
|
|
|
maxLength = False
|
|
|
|
tmp , placement = -1, 1
|
2017-09-30 05:47:24 +08:00
|
|
|
|
2017-02-25 23:06:58 +08:00
|
|
|
while not maxLength:
|
|
|
|
maxLength = True
|
|
|
|
# declare and initialize buckets
|
|
|
|
buckets = [list() for _ in range( RADIX )]
|
2017-09-30 05:47:24 +08:00
|
|
|
|
2017-02-25 23:06:58 +08:00
|
|
|
# split lst between lists
|
2017-10-12 03:58:12 +08:00
|
|
|
for i in lst:
|
|
|
|
tmp = int((i / placement) % RADIX)
|
|
|
|
buckets[tmp].append(i)
|
2017-10-23 21:47:45 +08:00
|
|
|
|
2017-02-25 23:06:58 +08:00
|
|
|
if maxLength and tmp > 0:
|
|
|
|
maxLength = False
|
2017-09-30 05:47:24 +08:00
|
|
|
|
2017-02-25 23:06:58 +08:00
|
|
|
# empty lists into lst array
|
|
|
|
a = 0
|
|
|
|
for b in range( RADIX ):
|
|
|
|
buck = buckets[b]
|
|
|
|
for i in buck:
|
|
|
|
lst[a] = i
|
|
|
|
a += 1
|
2017-09-30 05:47:24 +08:00
|
|
|
|
2017-02-25 23:06:58 +08:00
|
|
|
# move to next
|
|
|
|
placement *= RADIX
|