This commit is contained in:
Deinerovych 2024-11-08 14:35:33 +01:00
parent 8d2235827e
commit 436029f166

View File

@ -41,26 +41,6 @@ Node* parse_knowledge_base(char lines[][MAX_LINE_LENGTH], int *index, int line_c
return node;
}
int validate_tree_structure(char lines[][MAX_LINE_LENGTH], int line_count) {
int leaf_count = 0;
int question_count = 0;
for (int i = 0; i < line_count; i++) {
if (lines[i][0] == '*') {
leaf_count++;
} else {
question_count++;
if (i + 2 < line_count && lines[i + 1][0] == '*' && lines[i + 2][0] == '*') {
i += 2; // Skip the two leaves as expected
} else if (i + 1 < line_count && lines[i + 1][0] != '*') {
return 0; // Обнаружена некорректная структура (более двух дочерних узлов у вопроса)
}
}
}
return question_count >= leaf_count;
}
int count_products(Node *node) {
if (!node) return 0;
if (!node->yes && !node->no) return 1;
@ -121,7 +101,7 @@ int main() {
line_count++;
}
if (line_count == 0 || !validate_tree_structure(lines, line_count)) {
if (line_count == 0) {
printf("Expert z bufetu to vie.\n");
printf("Chybna databaza\n");
return 0;