From c26c09d58daccd5b3924296a8d5c58e74fe6312c Mon Sep 17 00:00:00 2001 From: JacksonMateus <48231382+JacksonMateus@users.noreply.github.com> Date: Fri, 18 Oct 2019 23:13:39 -0300 Subject: [PATCH] Create radixSort.py --- allalgorithms/sorting/radixSort.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 allalgorithms/sorting/radixSort.py diff --git a/allalgorithms/sorting/radixSort.py b/allalgorithms/sorting/radixSort.py new file mode 100644 index 0000000..ff384ae --- /dev/null +++ b/allalgorithms/sorting/radixSort.py @@ -0,0 +1,22 @@ +def radixSort(A): + RADIX = 10 + maxLength = False + tmp , placement = -1, 1 + + while not maxLength: + maxLength = True + buckets = [list() for _ in range(RADIX)] + for i in A: + tmp = i / placement + buckets[tmp % RADIX].append(i) + if maxLength and tmp > 0: + maxLength = False + + a = 0 + for b in range(RADIX): + buck = buckets[b] + for i in buck: + A[a] = i + a += 1 + placement *= RADIX + return A