We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d210cd1 + d9e1594 commit 146d9abCopy full SHA for 146d9ab
Sorting/RadixSort/python/radix_sort.py
@@ -0,0 +1,36 @@
1
+def counting_sort(arr, exp1):
2
+
3
+ n = len(arr)
4
5
+ output = [0] * (n)
6
7
+ count = [0] * (10)
8
9
+ for i in range(0, n):
10
+ index = (arr[i]/exp1)
11
+ count[(index)%10] += 1
12
13
+ for i in range(1,10):
14
+ count[i] += count[i-1]
15
16
+ i = n-1
17
+ while i >= 0:
18
+ index = arr[i]/exp1
19
+ output[ count[(index)%10] - 1] = arr[i]
20
+ count[(index)%10] -= 1
21
+ i -= 1
22
23
+ i = 0
24
+ for i in range(0,len(arr)):
25
+ arr[i] = output[i]
26
27
+def radix_sort(arr):
28
29
+ max1 = max(arr)
30
31
+ exp = 1
32
+ while max1/exp > 0:
33
+ countingSort(arr,exp)
34
+ exp *= 10
35
36
+radix_sort(arr)
0 commit comments