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); } }