From ca2b58c08eeee79e4053228702779ceba6f23584 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Sat, 21 Nov 2020 16:59:00 +0100 Subject: [PATCH] buffet --- cv8/program.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cv8/program.c b/cv8/program.c index 6f82738..e7fa091 100644 --- a/cv8/program.c +++ b/cv8/program.c @@ -36,8 +36,12 @@ struct tree* read_tree(){ return create_node(); }*/ if(buffer[0] != '*'){ - node->left = read_tree(); - node->right = read_tree(); + if(node->left == NULL){ + node->left = read_tree(); + } + if(node->right == NULL){ + node->right = read_tree(); + } } /*else if(string[0] == '*'){ if(node->left == NULL){ @@ -47,9 +51,9 @@ struct tree* read_tree(){ strcpy(node->value, string); } }*/ - //if(node->left != NULL && node->right != NULL){ + if(node->left != NULL && node->right != NULL){ return node; - //} + } } void print_tree(struct tree* node, int offset){ @@ -67,12 +71,13 @@ void print_tree(struct tree* node, int offset){ struct tree* search(struct tree* this, char answer){ if(this != NULL){ if(answer == 'a'){ + printf("%s\n", this->value); this->left = search(this, answer); } else if(answer == 'n'){ + printf("%s\n", this->value); this->right = search(this, answer); - } - + } } else{ exit(0); @@ -96,8 +101,7 @@ int count_l(struct tree* node){ return 1; } else{ - return count_l(node->left); - return count_l(node->right); + return count_l(node->left) + count_l(node->right); } }