This commit is contained in:
Anton Dolozin 2025-11-09 20:28:38 +01:00
parent f6ab3ecefd
commit f653b9ee4c

View File

@ -22,7 +22,16 @@ void destroy_tree(struct tree* tree){
} }
free(tree); free(tree);
} }
bool find_the_incorrect(struct tree* tree){
if(tree == NULL){
return false;
}
if(strcspn( tree->value, "*") != strlen(tree->value) || strcspn(tree->value, "?") != strlen(tree->value)){
return true;}
return find_the_incorrect(tree->right) || find_the_incorrect(tree->left);
}
struct tree* read_tree(){ struct tree* read_tree(){
char buffer[SIZE]; char buffer[SIZE];
memset(buffer,0,SIZE); memset(buffer,0,SIZE);
@ -69,9 +78,11 @@ int count_leaves(struct tree* tree){
int main(void){ int main(void){
bool whitespace = false; bool whitespace = false;
struct tree* tree = read_tree(); struct tree* tree = read_tree();
bool found = find_the_incorrect(tree);
print_tree(tree, 0);
char line[SIZE]; char line[SIZE];
char line2[SIZE];
int numOfLeaves = count_leaves(tree); int numOfLeaves = count_leaves(tree);
char answer[SIZE]; char answer[SIZE];
@ -82,8 +93,9 @@ int main(void){
break; break;
} }
} }
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
if(!tree || !whitespace){ if(!tree || !whitespace || found){
printf("Chybna databaza\n"); printf("Chybna databaza\n");
return 0; return 0;
} }
@ -125,3 +137,4 @@ int main(void){
} }
destroy_tree(tree); destroy_tree(tree);
return 0;} return 0;}