Fixed sorting_algorithms
This commit is contained in:
parent
c54dfca75d
commit
a5ee847442
1 changed files with 164 additions and 164 deletions
|
@ -97,7 +97,7 @@ class HeapSort(SortAlgorithm):
|
|||
|
||||
def build_heap(self, data):
|
||||
w = len(data)
|
||||
i = w/2-1
|
||||
i = int(w/2-1)
|
||||
while i>=0:
|
||||
self.heapify(data, i, w)
|
||||
i-=1
|
||||
|
@ -118,7 +118,7 @@ class MergeSort(SortAlgorithm):
|
|||
if len(a) <= 1:
|
||||
return a
|
||||
else:
|
||||
n = len(a)/2
|
||||
n = int(len(a)/2);
|
||||
return self.merge(self.mergesort(a[:n] or []), self.mergesort(a[n:] or []))
|
||||
|
||||
def merge(self,a,b):
|
||||
|
@ -205,8 +205,8 @@ def main():
|
|||
except Exception:
|
||||
size= 1000
|
||||
result = SortTester(list( SortAlgorithm.__subclasses__() )).test(size=size)
|
||||
for cls, r in result.items():
|
||||
print("%-12s: %10d, %d compares, %d swaps" % (cls.__name__, r[0]+r[1], r[0],r[1]))
|
||||
for cls, r in sorted(result.items(),key=lambda e: e[1][0]+e[1][1]):
|
||||
print("%-12s: %10d, %10d compares, %10d swaps" % (cls.__name__, r[0]+r[1], r[0],r[1]))
|
||||
|
||||
def test():
|
||||
print(HeapSort().sort([randint(0,500) for i in range(0,100)]))
|
||||
|
|
Loading…
Reference in a new issue