This commit is contained in:
Maryna Kravtsova 2020-11-22 18:13:56 +01:00
parent c4c808544f
commit c88245fafd

View File

@ -10,7 +10,8 @@ struct tree {
};
struct tree* read_tree(){
struct tree* read_tree(int* counter){
int* c = counter;
char buffer[50];
memset(buffer,0,50);
char* r = fgets(buffer,50,stdin);
@ -25,6 +26,8 @@ struct tree* read_tree(){
if(buffer[0] != '\0'){
struct tree* node = calloc(1,sizeof(struct tree));
memcpy(node->value, buffer,50);
*c += 1;
counter = &c;
if(buffer[0] != '*'){
if(node->left == NULL){
node->left = read_tree();
@ -33,6 +36,20 @@ struct tree* read_tree(){
node->right = read_tree();
}
}
if(node->left != NULL && node->right != NULL){
*c -= 2;
counter = &c;
}
if(c == 1){
r = fgets(buffer,50, stdin);
//int x = strlen(buffer);
// buffer[x-1]='\0';
if(buffer[0] != '\n'){
printf("Chybna databaza\n");
exit(0);
}
}
return node;
}
@ -139,8 +156,8 @@ int main(){
printf("Expert z bufetu to vie.\n");
struct tree* tree = NULL;
tree = read_tree();
int counter;
tree = read_tree(&counter);
int count = count_leaves(tree);
printf("Pozna %d druhov ovocia a zeleniny.\n", count);