From 3c4229fc9e0ec6da9a7f60b57b9e93c49d1b6b6c Mon Sep 17 00:00:00 2001 From: L0P0P Date: Thu, 27 Jun 2024 12:02:35 +0200 Subject: Fixed a lot of problems from all the progs we need to parse --- progs/a339.py | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'progs/a339.py') diff --git a/progs/a339.py b/progs/a339.py index 9a57403..95724d2 100644 --- a/progs/a339.py +++ b/progs/a339.py @@ -1,25 +1,28 @@ -def heap_sort(arr): - heapify(arr) - end = len(arr) - 1 - while end > 0: - arr[end], arr[0] = arr[0], arr[end] - shift_down(arr, 0, end - 1) - end -= 1 - return arr +# FIXME: chiamata a funzione definita dopo +# +# def heap_sort(arr): +# heapify(arr) +# end = len(arr) - 1 +# while end > 0: +# arr[end], arr[0] = arr[0], arr[end] +# shift_down(arr, 0, end - 1) +# end -= 1 +# return arr -def heapify(arr): - start = len(arr) // 2 - while start >= 0: - shift_down(arr, start, len(arr) - 1) - start -= 1 -def shift_down(arr, start, end): - root = start - while root * 2 + 1 <= end: - child = root * 2 + 1 - if child + 1 <= end and arr[child] < arr[child + 1]: - child += 1 - if child <= end and arr[root] < arr[child]: - arr[root], arr[child] = arr[child], arr[root] - root = child - else: - return +# def heapify(arr): +# start = len(arr) // 2 +# while start >= 0: +# shift_down(arr, start, len(arr) - 1) +# start -= 1 + +# def shift_down(arr, start, end): +# root = start +# while root * 2 + 1 <= end: +# child = root * 2 + 1 +# if child + 1 <= end and arr[child] < arr[child + 1]: +# child += 1 +# if child <= end and arr[root] < arr[child]: +# arr[root], arr[child] = arr[child], arr[root] +# root = child +# else: +# return -- cgit v1.2.3-18-g5258