mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Create radix_sort.py
This commit is contained in:
parent
94a30990e9
commit
e823c55f62
27
sorts/radix_sort.py
Normal file
27
sorts/radix_sort.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
def radixsort(lst):
|
||||
RADIX = 10
|
||||
maxLength = False
|
||||
tmp , placement = -1, 1
|
||||
|
||||
while not maxLength:
|
||||
maxLength = True
|
||||
# declare and initialize buckets
|
||||
buckets = [list() for _ in range( RADIX )]
|
||||
|
||||
# split lst between lists
|
||||
for i in lst:
|
||||
tmp = i / placement
|
||||
buckets[tmp % RADIX].append( i )
|
||||
if maxLength and tmp > 0:
|
||||
maxLength = False
|
||||
|
||||
# empty lists into lst array
|
||||
a = 0
|
||||
for b in range( RADIX ):
|
||||
buck = buckets[b]
|
||||
for i in buck:
|
||||
lst[a] = i
|
||||
a += 1
|
||||
|
||||
# move to next
|
||||
placement *= RADIX
|
Loading…
Reference in New Issue
Block a user