This commit is contained in:
Bohdan Kapliuk 2024-11-11 14:45:00 +02:00
parent a979bc49bc
commit 190e67862e

View File

@ -40,11 +40,8 @@ void destroy_tree(struct tree* tree) {
free(tree);
}
void print_tree(struct tree* tree, int offset) {
void print_tree(struct tree* tree) {
if (tree == NULL) return;
for (int i = 0; i < offset && tree->value[0] != '*'; i++) {
printf(" ");
}
printf("%s", tree->value);
if (tree->value[0] == '*') {
printf("Koniec\n");
@ -53,9 +50,9 @@ void print_tree(struct tree* tree, int offset) {
getchar();
char r = getchar();
if (r == 'a') {
print_tree(tree->left, offset + 3);
print_tree(tree->left);
} else if (r == 'n') {
print_tree(tree->right, offset + 3);
print_tree(tree->right);
} else if (r == EOF) {
printf("Koniec vstupu\n");
} else {
@ -66,12 +63,11 @@ void print_tree(struct tree* tree, int offset) {
int main() {
int counter = 0;
int offset = 0;
struct tree* root = read_tree(&counter);
printf("Expert z bufetu to vie.\n");
printf("Pozna %d druhov ovocia a zeleniny.\n", counter);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
print_tree(root, offset);
print_tree(root);
destroy_tree(root);
return 0;
}