From 2469d21681bbbc3039c2050e57cab12b1dbea967 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Sun, 22 Nov 2020 11:58:56 +0100 Subject: [PATCH] buffet --- cv8/program.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/cv8/program.c b/cv8/program.c index e69ebff..d0e492a 100644 --- a/cv8/program.c +++ b/cv8/program.c @@ -51,32 +51,27 @@ void print_tree(struct tree* node, int offset){ struct tree* search(struct tree* this){ - char buffer[5]; memset(buffer,0,5); char* r = fgets(buffer,5,stdin); int x = strlen(buffer); buffer[x-1]='\0'; - - if(buffer[0] != 'a' && buffer[0] != 'n'){ - printf("Chyba\n"); - exit(0); - } - if(this != NULL){ - if(buffer[0] == 'a'){ - printf("%s\n", this->value); - this->left = search(this); - } - else if(buffer[0] == 'n'){ - printf("%s\n", this->value); - this->right = search(this); - } + /*if(count ==){ + printf("%s\n", this->value); + }*/ + /*if(buffer[0] != 'a' || buffer[0] != 'n'){ + return NULL; + }*/ + if(buffer[0] == 'a'){ + printf("%s\n", this->value); + this = search(this->left); } - else{ - printf("Koniec\n"); - exit(0); - } - + else if(buffer[0] == 'n'){ + printf("%s\n", this->value); + this = search(this->right); + } + printf("Koniec\n"); + return this; } void destroy_tree(struct tree* root){ @@ -122,16 +117,18 @@ int main(){ struct tree* tree = NULL; tree = read_tree(); int count = count_leaves(tree); - + printf("Expert z bufetu to vie\n"); printf("Pozna %d druhov ovocia a zeleniny\n", count); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); - printf("%s\n", tree->value); + //printf("%s\n", tree->value); + //int all = count_all(tree); + tree = search(tree); //print_tree(tree, 3); //display(tree); - destroy_tree(tree); + //destroy_tree(tree); return 0; }