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){ struct tree* search(struct tree* this){
char buffer[5]; char buffer[5];
memset(buffer,0,5); memset(buffer,0,5);
char* r = fgets(buffer,5,stdin); char* r = fgets(buffer,5,stdin);
int x = strlen(buffer); int x = strlen(buffer);
buffer[x-1]='\0'; buffer[x-1]='\0';
/*if(count ==){
if(buffer[0] != 'a' && buffer[0] != 'n'){ printf("%s\n", this->value);
printf("Chyba\n"); }*/
exit(0); /*if(buffer[0] != 'a' || buffer[0] != 'n'){
} return NULL;
if(this != NULL){ }*/
if(buffer[0] == 'a'){ if(buffer[0] == 'a'){
printf("%s\n", this->value); printf("%s\n", this->value);
this->left = search(this); this = search(this->left);
}
else if(buffer[0] == 'n'){
printf("%s\n", this->value);
this->right = search(this);
}
} }
else{ else if(buffer[0] == 'n'){
printf("Koniec\n"); printf("%s\n", this->value);
exit(0); this = search(this->right);
} }
printf("Koniec\n");
return this;
} }
void destroy_tree(struct tree* root){ void destroy_tree(struct tree* root){
@ -122,16 +117,18 @@ int main(){
struct tree* tree = NULL; struct tree* tree = NULL;
tree = read_tree(); tree = read_tree();
int count = count_leaves(tree); int count = count_leaves(tree);
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);
//int all = count_all(tree);
tree = search(tree); tree = search(tree);
//print_tree(tree, 3); //print_tree(tree, 3);
//display(tree); //display(tree);
destroy_tree(tree); //destroy_tree(tree);
return 0; return 0;
} }