This commit is contained in:
Maryna Kravtsova 2020-11-22 11:58:56 +01:00
parent 5c6d8f47dc
commit 2469d21681

View File

@ -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;
}