This commit is contained in:
Anton Dolozin 2025-11-09 20:45:09 +01:00
parent 4b4afb5334
commit dc8019ad2d

View File

@ -22,16 +22,7 @@ void destroy_tree(struct tree* 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(){
char buffer[SIZE];
memset(buffer,0,SIZE);
@ -52,6 +43,18 @@ struct tree* read_tree(){
node->right = read_tree();
return node;
}
bool find_the_incorrect(struct tree* tree) {
if (tree == NULL)
return false;
if (tree->value &&
(strcspn(tree->value, "*") != strlen(tree->value) &&
strcspn(tree->value, "?") != strlen(tree->value))) {
return true;
}
return find_the_incorrect(tree->left) || find_the_incorrect(tree->right);
}
void print_tree(struct tree* tree,int offset){
for (int i = 0; i < offset; i++){
printf(" ");
@ -78,8 +81,8 @@ int count_leaves(struct tree* tree){
int main(void){
bool whitespace = false;
struct tree* tree = read_tree();
bool found = find_the_incorrect(tree);
char line[SIZE];
int numOfLeaves = count_leaves(tree);
@ -91,7 +94,7 @@ int main(void){
break;
}
}
bool found = find_the_incorrect(tree);
printf("Expert z bufetu to vie.\n");
if(!tree || !whitespace || found){
printf("Chybna databaza\n");
@ -134,5 +137,4 @@ int main(void){
}
}
destroy_tree(tree);
return 0;}
return 0;}