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){
int c = getchar();
if(this == NULL || this->value[0] == '*'){
return this;
}
void search(struct tree* this){
if(c == 'a'){
char buffer[5];
memset(buffer,0,5);
char* r = fgets(buffer,5,stdin);
int x = strlen(buffer);
buffer[x-1]='\0';
if(this == NULL){
return;
}
if(buffer[0] == 'a'){
if(this->left->value[0] == '*'){
printf("%s\n", this->left->value);
return;
}
printf("%s\n", this->left->value);
return search(this->left);
search(this->left);
}
else if(c == 'n'){
else if(buffer[0] == 'n'){
if(this->right->value[0] == '*'){
printf("%s\n", this->right->value);
return;
}
printf("%s\n", this->right->value);
return search(this->right);
search(this->right);
}
}
@ -140,8 +155,8 @@ int main(){
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);
tree = search(tree);
//printf("%s\n", tree->value);
search(tree);
destroy_tree(tree);
printf("Koniec\n");
return 0;