From 3b9cbe3f4c2cb666fc4bd967dfb2b8b42f13e9c8 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Sun, 22 Nov 2020 13:13:44 +0100 Subject: [PATCH] buffet --- cv8/program.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/cv8/program.c b/cv8/program.c index 5f2e4a6..f9e9759 100644 --- a/cv8/program.c +++ b/cv8/program.c @@ -18,49 +18,39 @@ struct tree* read_tree(){ buffer[x-1]='\0'; assert(r); - if(buffer[0] == '\0'){ - return NULL; - } - - - struct tree* node = calloc(1,sizeof(struct tree)); - /*if(buffer[0] == '\0'){ - return node; - }*/ - memcpy(node->value, buffer,50); - if(buffer[0] != '*'){ - if(node->left == NULL){ - node->left = read_tree(); - } - if(node->right == NULL){ - node->right = read_tree(); - } - } + if(buffer[0] != '\0'){ + + struct tree* node = calloc(1,sizeof(struct tree)); + memcpy(node->value, buffer,50); + if(buffer[0] != '*'){ + if(node->left == NULL){ + node->left = read_tree(); + } + if(node->right == NULL){ + node->right = read_tree(); + } + } //if(node->left != NULL && node->right != NULL){ return node; + } // } } struct tree* search(struct tree* this){ - /*char question[30] = "Je to ovocie alebo zelenina"; - if(strcmp(this->value,question) == 0){ - printf("%s\n", this->value); - this = search(this); - }*/ char c = getchar(); /*char buffer[50]; memset(buffer, 0, 50); int x = strlen(buffer); buffer[x-1]='\0'; memcpy(buffer, this->value, 50); */ - if(this != 0){ + if(this != NULL){ if(c == 'a'){ printf("%s\n", this->value); - this = search(this->left); + this->left = search(this->left); } else if(c == 'n'){ printf("%s\n", this->value); - this = search(this->right); + this->right = search(this->right); } }