mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
02c0daf9e5
* Adding variable to fade out ambiguity * More readability on merge sorting algorithm * Updating merge_sort_fastest description and explaining why * Adding tests file with imports * Standardazing filenames and function names * Adding test cases and test functions * Adding test loop * Putting 'user oriented code' inside main condition for having valid imports * Fixing condition * Updating tests: adding cases and todo list * Refactoring first euler problem's first solution
27 lines
571 B
Python
27 lines
571 B
Python
def radix_sort(lst):
|
|
RADIX = 10
|
|
placement = 1
|
|
|
|
# get the maximum number
|
|
max_digit = max(lst)
|
|
|
|
while placement < max_digit:
|
|
# declare and initialize buckets
|
|
buckets = [list() for _ in range( RADIX )]
|
|
|
|
# split lst between lists
|
|
for i in lst:
|
|
tmp = int((i / placement) % RADIX)
|
|
buckets[tmp].append(i)
|
|
|
|
# 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
|