From 0be6e351cbed47eac543e74878413f8ea34207f2 Mon Sep 17 00:00:00 2001 From: prototype-raj <52649525+prototype-raj@users.noreply.github.com> Date: Sat, 2 Oct 2021 00:14:24 +0530 Subject: [PATCH] Added Radix sort python program --- radix_sort_py.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 radix_sort_py.py diff --git a/radix_sort_py.py b/radix_sort_py.py new file mode 100644 index 0000000..97f780a --- /dev/null +++ b/radix_sort_py.py @@ -0,0 +1,31 @@ +# python program for counting sort + +def countingSort(arr): + size = len(arr) + output = [0] * size + + # count array initialization + count = [0] * 10 + + # storing the count of each element + for m in range(0, size): + count[arr[m]] += 1 + + # storing the cumulative count + for m in range(1, 10): + count[m] += count[m - 1] + + # place the elements in output array after finding the index of each element of original array in count array + m = size - 1 + while m >= 0: + output[count[arr[m]] - 1] = arr[m] + count[arr[m]] -= 1 + m -= 1 + + for m in range(0, size): + arr[m] = output[m] + +data = [3,5,1,6,7,8,3] +countingSort(data) +print("Sorted Array: ") +print(data) \ No newline at end of file