buffet
This commit is contained in:
parent
1c3fdbd255
commit
1fc66d2e64
@ -37,19 +37,30 @@ struct tree* read_tree(){
|
|||||||
struct tree* search(struct tree* this){
|
struct tree* search(struct tree* this){
|
||||||
|
|
||||||
int c = getchar();
|
int c = getchar();
|
||||||
|
if(this == NULL || this->value[0] == '*'){
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
if(this->left != NULL && this->right != NULL){
|
|
||||||
if(c == 'a'){
|
if(c == 'a'){
|
||||||
//this->left = search(this->left);
|
|
||||||
printf("%s\n", this->left->value);
|
printf("%s\n", this->left->value);
|
||||||
this->left = search(this->left);
|
return search(this->left);
|
||||||
}
|
}
|
||||||
else if(c == 'n'){
|
else if(c == 'n'){
|
||||||
//this->right = search(this->right);
|
|
||||||
printf("%s\n", this->right->value);
|
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){
|
void destroy_tree(struct tree* root){
|
||||||
@ -95,11 +106,11 @@ 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);
|
||||||
|
//print_tree(tree, 3);
|
||||||
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);
|
||||||
tree = search(tree);
|
tree = search(tree);
|
||||||
//destroy_tree(tree);
|
//destroy_tree(tree);
|
||||||
printf("Koniec\n");
|
printf("Koniec\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user