test
This commit is contained in:
parent
aeb513ec40
commit
7e07d88bd4
35
a4/program.c
35
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()
|
Loading…
Reference in New Issue
Block a user