Browse Source

Create radix_sort.py

pull/2/head
Adriano Laureano 6 years ago
committed by GitHub
parent
commit
e2ff29c04b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions
  1. +14
    -0
      sorting/radix_sort.py

+ 14
- 0
sorting/radix_sort.py View File

@ -0,0 +1,14 @@
def radix_sort(lista):
max_len = max([len(numero) for numero in lista])
padded = list([str(num).rjust(max_len, "0") for num in lista])
for pos in reversed(range(max_len)):
buckets = [list() for x in range(0, 10)]
for num in padded:
bucket = int(num[pos])
buckets[bucket] += [num]
padded = sum(buckets, [])
return padded
if __name__ == "__main__":
print(radix_sort(["13", "105", "10", "150"]))

Loading…
Cancel
Save