This commit is contained in:
Jana Kapalková 2026-04-16 13:30:29 +02:00
parent d4c98240d0
commit d3d9dd7ab6

View File

@ -29,12 +29,7 @@ struct Node* read_tree(void) {
if (buffer[0] != '*') {
node->left = read_tree();
if (node->left == NULL) {
destroy_tree(node);
return NULL;
}
node->right = read_tree();
if (node->right == NULL) {
if (node->left == NULL || node->right == NULL) {
destroy_tree(node);
return NULL;
}
@ -60,12 +55,12 @@ void run_system(struct Node* node) {
if (fgets(answer, SIZE, stdin) == NULL) return;
answer[strcspn(answer, "\r\n")] = '\0';
if (strcmp(answer, "y") == 0) {
if (strcmp(answer, "a") == 0) {
run_system(node->left);
} else if (strcmp(answer, "n") == 0) {
run_system(node->right);
} else {
printf("I don't understand\n");
return;
}
}
@ -82,9 +77,9 @@ int main(void) {
return 1;
}
int leaves = count_leaves(root);
printf("The Expert System is ready.\n");
printf("It knows %d types of fruits and vegetables.\n", leaves);
printf("Answer 'y' (yes) or 'n' (no)\n");
printf("Expert z bufetu to vie.\n");
printf("Pozna %d druhov ovocia a zeleniny.\n", leaves);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
run_system(root);
destroy_tree(root);