26
This commit is contained in:
		
							parent
							
								
									80e2744b60
								
							
						
					
					
						commit
						e6fcb73d14
					
				| @ -29,21 +29,21 @@ Node* parse_knowledge_base(FILE *file) { | ||||
|         return NULL; | ||||
|     } | ||||
| 
 | ||||
|     line[strcspn(line, "\n")] = 0; // Убираем символ новой строки
 | ||||
|     line[strcspn(line, "\n")] = 0; // Remove newline character
 | ||||
| 
 | ||||
|     if (line[0] == '*') { | ||||
|         return create_node(line + 1); // Создаем узел-ответ, пропуская '*'
 | ||||
|         return create_node(line + 1); // Create answer node, skip '*'
 | ||||
|     } else { | ||||
|         Node *node = create_node(line); | ||||
|         node->yes = parse_knowledge_base(file); // Рекурсивно читаем ответ "да"
 | ||||
|         node->no = parse_knowledge_base(file);  // Рекурсивно читаем ответ "нет"
 | ||||
|         node->yes = parse_knowledge_base(file); // Recursively read "yes" answer
 | ||||
|         node->no = parse_knowledge_base(file);  // Recursively read "no" answer
 | ||||
|         return node; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int count_products(Node *node) { | ||||
|     if (!node) return 0; | ||||
|     if (!node->yes && !node->no) return 1; // Если узел - лист (ответ)
 | ||||
|     if (!node->yes && !node->no) return 1; // If node is a leaf (answer)
 | ||||
|     return count_products(node->yes) + count_products(node->no); | ||||
| } | ||||
| 
 | ||||
| @ -52,7 +52,7 @@ void run_expert_system(Node *node) { | ||||
|         printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); | ||||
|         printf("%s\n", node->text); | ||||
| 
 | ||||
|         // Print the options and then the answer if it's a leaf node.
 | ||||
|         // Print the answer if it's a leaf node.
 | ||||
|         if (!node->yes && !node->no) { | ||||
|             printf("*%s\n", node->text); | ||||
|             printf("Koniec\n"); | ||||
| @ -61,17 +61,17 @@ void run_expert_system(Node *node) { | ||||
| 
 | ||||
|         char answer; | ||||
|         if (scanf(" %c", &answer) != 1) { | ||||
|             printf("Koniec\n"); // Некорректный ввод, завершение
 | ||||
|             printf("Koniec\n"); // Incorrect input, termination
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         // Переходим к следующему узлу на основе ответа пользователя
 | ||||
|         // Move to the next node based on user's answer
 | ||||
|         if (answer == 'a') { | ||||
|             node = node->yes; | ||||
|         } else if (answer == 'n') { | ||||
|             node = node->no; | ||||
|         } else { | ||||
|             printf("Koniec\n"); // Некорректный ответ, завершение
 | ||||
|             printf("Koniec\n"); // Incorrect answer, termination
 | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user