-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradixSort.py
More file actions
43 lines (43 loc) · 1.04 KB
/
radixSort.py
File metadata and controls
43 lines (43 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
list = [64, 8, 216, 512, 27, 729, 0, 1, 343, 125]
def firstPass(A):
aux = {}
for i in range(10):
aux[i] = []
for i in range(len(A)):
tens = A[i] % 10
aux[tens].append(A[i])
index = 0
for digit in range(10):
for number in aux[digit]:
A[index] = number
index += 1
def secondPass(A):
aux = {}
for i in range(10):
aux[i] = []
for i in range(len(A)):
hundreds = (A[i] // 10) % 10
aux[hundreds].append(A[i])
index = 0
for hundredth in range(10):
for number in aux[hundredth]:
A[index] = number
index += 1
def thirdPass(A):
aux = {}
for i in range(10):
aux[i] = []
for i in range(len(A)):
thousands = (A[i] // 100) % 10
aux[thousands].append(A[i])
index = 0
for thousandth in range(10):
for number in aux[thousandth]:
A[index] = number
index += 1
def radixSort(A):
firstPass(A)
secondPass(A)
thirdPass(A)
radixSort(list)
print(list)