-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathm2t7.py
More file actions
46 lines (38 loc) · 1.21 KB
/
m2t7.py
File metadata and controls
46 lines (38 loc) · 1.21 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
44
45
46
#Поразрядная сортировка
stringCount = int(input())
stringList = []
for i in range(stringCount):
stringList.append(input())
def radixSort(array, elementLength, abLength):
process = []
for i in range(abLength):
process.append([])
for i in range(elementLength - 1, -1, -1):
for j in range(len(array)):
process[int(array[j][i])].append(array[j])
count = 0
for j in range(len(process)):
for k in range(len(process[j])):
array[count] = process[j][k]
count += 1
printPhase(process, elementLength - i)
clearProcess(process, abLength)
def printPhase(array, phaseCount):
print("Phase " + str(phaseCount))
for i in range(len(array)):
value = ""
if len(array[i]) == 0:
value = "empty"
else:
value = ", ".join(array[i])
print("Bucket " + str(i) + ": " + value)
print("*" * 10)
def clearProcess(process, abLength):
for i in range(abLength):
process[i] = []
print("Initial array:")
print(", ".join(stringList))
print("*" * 10)
radixSort(stringList, len(stringList[0]), 10)
print("Sorted array:")
print(", ".join(stringList))