forked from hofmannol/AlgoDatSoSe25
Quick Sort and Heap Sort
This commit is contained in:
parent
27a37037d1
commit
1af49ede8c
@ -21,9 +21,7 @@ def merge_sort_stepwise(z: MemoryArray, l: Literal = None, r: Literal = None, bu
|
|||||||
yield from merge(z, l, m, r, buffer)
|
yield from merge(z, l, m, r, buffer)
|
||||||
|
|
||||||
def merge(z: MemoryArray, l: Literal, m: Literal, r: Literal, buffer: MemoryArray):
|
def merge(z: MemoryArray, l: Literal, m: Literal, r: Literal, buffer: MemoryArray):
|
||||||
i = MemoryCell(l)
|
with MemoryCell(l) as i, MemoryCell(m.succ()) as j, MemoryCell(l) as k:
|
||||||
j = MemoryCell(m.succ())
|
|
||||||
k = MemoryCell(l)
|
|
||||||
while i <= m and j <= r:
|
while i <= m and j <= r:
|
||||||
if z[i] <= z[j]:
|
if z[i] <= z[j]:
|
||||||
buffer[k].set(z[i])
|
buffer[k].set(z[i])
|
||||||
@ -51,7 +49,6 @@ def merge_sort(z: MemoryArray):
|
|||||||
next(sort_generator)
|
next(sort_generator)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
# print(len(z), z.count_compares(), MemoryManager.get_instance().count_compares())
|
|
||||||
|
|
||||||
def sort_file(filename, sort_func):
|
def sort_file(filename, sort_func):
|
||||||
z = MemoryArray.create_array_from_file(filename)
|
z = MemoryArray.create_array_from_file(filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user