This commit is contained in:
Maryna Kravtsova 2020-11-22 15:59:48 +01:00
parent f6f5f0ce94
commit cfb3f31df3

View File

@ -34,20 +34,35 @@ struct tree* read_tree(){
} }
} }
struct tree* search(struct tree* this){ void search(struct tree* this){
int c = getchar(); char buffer[5];
if(this == NULL || this->value[0] == '*'){ memset(buffer,0,5);
return this; char* r = fgets(buffer,5,stdin);
int x = strlen(buffer);
buffer[x-1]='\0';
if(this == NULL){
return;
} }
if(buffer[0] == 'a'){
if(c == 'a'){ if(this->left->value[0] == '*'){
printf("%s\n", this->left->value); printf("%s\n", this->left->value);
return search(this->left); return;
} }
else if(c == 'n'){ printf("%s\n", this->left->value);
search(this->left);
}
else if(buffer[0] == 'n'){
if(this->right->value[0] == '*'){
printf("%s\n", this->right->value); printf("%s\n", this->right->value);
return search(this->right); return;
}
printf("%s\n", this->right->value);
search(this->right);
} }
} }
@ -140,8 +155,8 @@ int main(){
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
printf("Pozna %d druhov ovocia a zeleniny.\n", count); printf("Pozna %d druhov ovocia a zeleniny.\n", count);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
printf("%s\n", tree->value); //printf("%s\n", tree->value);
tree = search(tree); search(tree);
destroy_tree(tree); destroy_tree(tree);
printf("Koniec\n"); printf("Koniec\n");
return 0; return 0;