wejnrfnw
This commit is contained in:
parent
4b4afb5334
commit
dc8019ad2d
@ -22,16 +22,7 @@ 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);
|
||||||
@ -52,6 +43,18 @@ struct tree* read_tree(){
|
|||||||
node->right = read_tree();
|
node->right = read_tree();
|
||||||
return node;
|
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){
|
void print_tree(struct tree* tree,int offset){
|
||||||
for (int i = 0; i < offset; i++){
|
for (int i = 0; i < offset; i++){
|
||||||
printf(" ");
|
printf(" ");
|
||||||
@ -78,8 +81,8 @@ 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);
|
|
||||||
char line[SIZE];
|
char line[SIZE];
|
||||||
|
|
||||||
int numOfLeaves = count_leaves(tree);
|
int numOfLeaves = count_leaves(tree);
|
||||||
@ -91,7 +94,7 @@ int main(void){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool found = find_the_incorrect(tree);
|
||||||
printf("Expert z bufetu to vie.\n");
|
printf("Expert z bufetu to vie.\n");
|
||||||
if(!tree || !whitespace || found){
|
if(!tree || !whitespace || found){
|
||||||
printf("Chybna databaza\n");
|
printf("Chybna databaza\n");
|
||||||
@ -134,5 +137,4 @@ int main(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
destroy_tree(tree);
|
destroy_tree(tree);
|
||||||
return 0;}
|
return 0;}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user