This commit is contained in:
Maryna Kravtsova 2020-11-22 14:59:10 +01:00
parent 1c3fdbd255
commit 1fc66d2e64

View File

@ -37,18 +37,29 @@ struct tree* read_tree(){
struct tree* search(struct tree* this){
int c = getchar();
if(this == NULL || this->value[0] == '*'){
return this;
}
if(this->left != NULL && this->right != NULL){
if(c == 'a'){
//this->left = search(this->left);
printf("%s\n", this->left->value);
this->left = search(this->left);
return search(this->left);
}
else if(c == 'n'){
//this->right = search(this->right);
printf("%s\n", this->right->value);
this->right = search(this->right);
return search(this->right);
}
}
void print_tree(struct tree* tree,int offset){
int i;
for (i = 0; i < offset; i++){
printf(" ");
}
printf("%s",tree->value);
if (tree->left){
print_tree(tree->left,offset +3);
print_tree(tree->right,offset +3);
}
}
@ -95,11 +106,11 @@ int main(){
struct tree* tree = NULL;
tree = read_tree();
int count = count_leaves(tree);
//print_tree(tree, 3);
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);
tree = search(tree);
//destroy_tree(tree);
printf("Koniec\n");