buffet
This commit is contained in:
parent
1c3fdbd255
commit
1fc66d2e64
@ -37,21 +37,32 @@ struct tree* read_tree(){
|
||||
struct tree* search(struct tree* this){
|
||||
|
||||
int c = getchar();
|
||||
|
||||
if(this->left != NULL && this->right != NULL){
|
||||
if(this == NULL || this->value[0] == '*'){
|
||||
return this;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_tree(struct tree* root){
|
||||
if(root == NULL) return;
|
||||
|
||||
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user