This commit is contained in:
Anton Dolozin 2025-11-09 21:25:11 +01:00
parent a480aa16fe
commit 75cc8ff554

View File

@ -79,16 +79,12 @@ int count_leaves(struct tree* tree){
} }
} }
int count_non_leaves(struct tree* tree){ int count_non_leaves(struct tree* tree){
if(tree == NULL || (tree->left == NULL && tree->right == NULL)){ if(tree == NULL || ( tree->left== NULL && tree->right ==NULL)){
return 0; return 0;
} }
return 1 + count_non_leaves(tree->left) +count_non_leaves(tree->right);
return 1+ count_non_leaves(tree->left) + count_non_leaves(tree->right);
} }
int main(void){ int main(void){
bool whitespace = false; bool whitespace = false;
@ -96,6 +92,7 @@ int main(void){
char line[SIZE]; char line[SIZE];
int numOfLeaves = count_leaves(tree); int numOfLeaves = count_leaves(tree);
int numOfNonLeaves = count_non_leaves(tree);
char answer[SIZE]; char answer[SIZE];
while (fgets(line, sizeof(line), stdin)) { while (fgets(line, sizeof(line), stdin)) {
line[strcspn(line, "\n")] = '\0'; line[strcspn(line, "\n")] = '\0';
@ -103,12 +100,10 @@ int main(void){
whitespace = true; whitespace = true;
break; break;
} }
} };
int res = count_non_leaves(tree);
int res2 = numOfLeaves - res;
bool found = find_the_incorrect(tree); bool found = find_the_incorrect(tree);
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
if(!tree || !whitespace || found || res2 < 1){ if(!tree || !whitespace || found || strcmp(tree->value, "Je to ovocie alebo zelenina") != 0){
printf("Chybna databaza\n"); printf("Chybna databaza\n");
return 0; return 0;
} }