diff --git a/a4/program.c b/a4/program.c index e69de29..2ff26a7 100644 --- a/a4/program.c +++ b/a4/program.c @@ -0,0 +1,35 @@ +def is_min_heap(arr): + n = len(arr) + for i in range(n): + l = 2 * i + 1 + r = 2 * i + 2 + if l < n and arr[i] > arr[l]: + return False + if r < n and arr[i] > arr[r]: + return False + return True + +def preorder(arr, index, level): + if index >= len(arr): + return + print(' ' * level + str(arr[index])) + l = 2 * index + 1 + r = 2 * index + 2 + if l < len(arr): + preorder(arr, l, level + 1) + if r < len(arr): + preorder(arr, r, level + 1) + +def main(): + # Načítanie vstupu + arr = list(map(int, input().split())) + + if is_min_heap(arr): + print("Je to taka kopa:") + preorder(arr, 0, 0) + else: + print("Nie je kopa.") + + +if __name__ == "__main__": + main()