From be4b8cb12ecd16b450ee40f0ddeb6029e5a9c15b Mon Sep 17 00:00:00 2001 From: Weber Date: Wed, 27 Nov 2024 18:27:03 +0000 Subject: [PATCH] test --- a4/program.c | 67 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/a4/program.c b/a4/program.c index 2ff26a7..43844cc 100644 --- a/a4/program.c +++ b/a4/program.c @@ -1,35 +1,38 @@ -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 +#include +#include -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) +bool is_min_heap(int arr[], int n) { + for (int i = 0; i < n; i++) { + int l = 2 * i + 1; + int r = 2 * i + 2; + if ((l < n && arr[i] > arr[l]) || (r < n && arr[i] > arr[r])) { + return false; + } + } + return true; +} -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.") +void preorder(int arr[], int n, int index, int level) { + if (index >= n) return; + for (int i = 0; i < level; i++) { + printf(" "); + } + printf("%d\n", arr[index]); + preorder(arr, n, 2 * index + 1, level + 1); + preorder(arr, n, 2 * index + 2, level + 1); +} - -if __name__ == "__main__": - main() +int main() { + int arr[100]; + int n = 0; + while (scanf("%d", &arr[n]) != EOF) { + n++; + } + if (is_min_heap(arr, n)) { + printf("Je to taka kopa:\n"); + preorder(arr, n, 0, 0); + } else { + printf("Nie je kopa.\n"); + } + return 0; +}