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(buffer[0] == 'a'){
printf("%s\n", this->value);
this = search(this->left);
} }
if(this != NULL){ else if(buffer[0] == 'n'){
if(buffer[0] == 'a'){ printf("%s\n", this->value);
printf("%s\n", this->value); this = search(this->right);
this->left = search(this);
}
else if(buffer[0] == 'n'){
printf("%s\n", this->value);
this->right = search(this);
}
} }
else{ printf("Koniec\n");
printf("Koniec\n"); return this;
exit(0);
}
} }
void destroy_tree(struct tree* root){ void destroy_tree(struct tree* root){
@ -126,12 +121,14 @@ 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);
//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;
} }