diff --git a/Sorting/Radix_Sort.py b/Sorting/Radix_Sort.py new file mode 100644 index 0000000..93e5fd5 --- /dev/null +++ b/Sorting/Radix_Sort.py @@ -0,0 +1,31 @@ +# Radix sort + +def countingSort(array, place): + size = len(array) + output = [0] * size + count = [0] * 10 + for i in range(0, size): + index = array[i] // place + count[index % 10] += 1 + for i in range(1, 10): + count[i] += count[i - 1] + i = size - 1 + while i >= 0: + index = array[i] // place + output[count[index % 10] - 1] = array[i] + count[index % 10] -= 1 + i -= 1 + for i in range(0, size): + array[i] = output[i] + +def radixSort(array): + max_element = max(array) + place = 1 + while max_element // place > 0: + countingSort(array, place) + place *= 10 + + +data = [121, 432, 564, 23, 1, 45, 788] +radixSort(data) +print(data) \ No newline at end of file
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: