Skip to content

Commit 1330553

Browse files
authored
Merge pull request BeeBombshell#122 from kpriyanshi02/patch-1
Created Radix.py
2 parents ce07bcf + 178f05b commit 1330553

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Sort-all/Radix.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def counting_Sort(array, exp1):
2+
n = len(arr)
3+
output = [0] * (n)
4+
count = [0] * (10)
5+
for i in range(0, n):
6+
index = (arr[i]/exp1)
7+
count[int((index)%10)] += 1
8+
for i in range(1,10):
9+
count[i] += count[i-1]
10+
i = n-1
11+
while i>=0:
12+
index = (arr[i]/exp1)
13+
output[ count[ int((index)%10) ] - 1] = arr[i]
14+
count[int((index)%10)] -= 1
15+
i -= 1
16+
i = 0
17+
for i in range(0,len(arr)):
18+
arr[i] = output[i]
19+
def radixSort(arr):
20+
max1 = max(arr)
21+
exp = 1
22+
while max1/exp > 0:
23+
counting_Sort(arr,exp)
24+
exp *= 10
25+
arr = [ 170, 45, 75, 90, 802, 24, 2, 66]
26+
radixSort(arr)
27+
for i in range(len(arr)):
28+
print(arr[i],end=" ")
29+

0 commit comments

Comments
 (0)