-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathRadixSort.py
33 lines (24 loc) · 844 Bytes
/
RadixSort.py
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
def radixSort(listToBeSorted):
cyphers = 10
maxLength = False
placement = 1
while not maxLength:
maxLength = True
buckets = [list() for _ in range(cyphers)]
for i in listToBeSorted:
tmp = i // placement
buckets[tmp % cyphers].append(i)
if maxLength and tmp > 0:
maxLength = False
element = 0
for cipher in range(cyphers):
bucket = buckets[cipher]
for buck in bucket:
listToBeSorted[element] = buck
element += 1
placement *= cyphers
print ("Input integers you want to sort, seperated by spaces.")
inputList = [int(i) for i in input().split()]
print ("List to be sorted: {0}".format(inputList))
radixSort(inputList)
print ("The sorted list: {0}".format(inputList))