-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradix.py
60 lines (50 loc) · 1.54 KB
/
radix.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Algorthms GUI Project / radix.py
# Created on: 07-Nov-2018
# Author: Gourav Siddhad
# Radix Sort
from employee import Employee
class Radix():
def __init__(self):
self.emp = []
self.output = []
def read_File(self, inputFile):
fin = open(inputFile, 'r')
i = 0
for line in fin.readlines():
self.emp.append(Employee(i))
self.output.append(Employee(i))
a, b, c, d = line.split()
self.emp[i].putData(a, b, c, d)
i = i + 1
def getMax(self):
max = 0
for e in self.emp:
if max < e.getSalary():
max = e.getSalary()
return max
def sort(self):
max = self.getMax()
exp = 1
while (max // exp) > 0:
count = [0] * (10)
for i in range(0, len(self.emp)):
n = (self.emp[i].getSalary() // exp) % 10
count[n] = count[n] + 1
for i in range(1, 10):
count[i] = count[i] + count[i - 1]
i = len(self.emp) - 1
while i >= 0:
n = (self.emp[i].getSalary() // exp) % 10
self.output[count[n] - 1] = self.emp[i]
count[n] = count[n] - 1
i = i - 1
i = 0
for o in self.output:
self.emp[i] = o
i = i + 1
exp = exp * 10
def displayOutput(self):
output = ''
for o in self.output:
output = output + str(o.display()) + '\n'
return output