From e14c23ba016c568b5ffd6c8d93a95d2cfcaeefec Mon Sep 17 00:00:00 2001 From: Kozar Date: Tue, 12 Nov 2024 16:14:39 +0000 Subject: [PATCH] Initializacia --- cv7/program.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/cv7/program.c b/cv7/program.c index 6cfe83f..266a371 100644 --- a/cv7/program.c +++ b/cv7/program.c @@ -1,5 +1,6 @@ #include #include +#include #include #define SIZE 100 @@ -17,7 +18,7 @@ struct tree* read_tree() { if (!r || buffer[0] == '\n') { return NULL; } - buffer[strcspn(buffer, "\n")] = 0; + buffer[strcspn(buffer, "\n")] = 0; struct tree* node = calloc(1, sizeof(struct tree)); strncpy(node->value, buffer, SIZE - 1); return node; @@ -28,12 +29,10 @@ struct tree* load_tree() { if (!node) { return NULL; } - if (node->value[0] != '*') { node->left = load_tree(); node->right = load_tree(); } - return node; } @@ -66,20 +65,16 @@ void run_tree(struct tree* tree) { } void destroy_tree(struct tree* tree) { - if (!tree) { - return; + if (tree->left != NULL) { + destroy_tree(tree->left); + } + if (tree->right != NULL) { + destroy_tree(tree->right); } - - destroy_tree(tree->left); - destroy_tree(tree->right); free(tree); } void count_items(struct tree* tree, int* count) { - if (!tree) { - return; - } - if (tree->left == NULL && tree->right == NULL) { (*count)++; } else { @@ -90,9 +85,7 @@ void count_items(struct tree* tree, int* count) { int main() { struct tree* root = load_tree(); - printf("Expert z bufetu to vie.\n"); - if (!root) { printf("Chybna databaza\n"); return 0;