From 36f9d01893e420881bab9b09385881d6b68e7aa3 Mon Sep 17 00:00:00 2001 From: Kozar Date: Tue, 12 Nov 2024 15:56:01 +0000 Subject: [PATCH] Initializacia --- cv7/program.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cv7/program.c b/cv7/program.c index 266a371..de4cd79 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -29,9 +29,13 @@ struct tree* load_tree() { if (!node) { return NULL; } - if (node->value[0] != '*') { + + if (node->value[0] != '*') { node->left = load_tree(); node->right = load_tree(); + } else { + node->left = NULL; + node->right = NULL; } return node; } @@ -42,7 +46,7 @@ void run_tree(struct tree* tree) { } if (tree->value[0] == '*') { - printf("*%s\nKoniec\n", tree->value + 1); + printf("%s\nKoniec\n", tree->value + 1); return; } @@ -78,8 +82,8 @@ void count_items(struct tree* tree, int* count) { if (tree->left == NULL && tree->right == NULL) { (*count)++; } else { - count_items(tree->left, count); - count_items(tree->right, count); + if (tree->left) count_items(tree->left, count); + if (tree->right) count_items(tree->right, count); } }