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