Update cv7/program.c

This commit is contained in:
Yurii Yakovenko 2024-11-11 22:13:27 +00:00
parent cba7e62977
commit bf7202663e

View File

@ -20,7 +20,11 @@ struct tree* read_tree()
memset(buffer,0,SIZE);
char* r = fgets(buffer,SIZE,stdin);
assert(r);
if(buffer[0]=='\n')
return NULL;
struct tree* node = (struct tree*)calloc(1,sizeof(struct tree));
memcpy(node->value,buffer,SIZE);
@ -53,6 +57,13 @@ void print_tree(struct tree* tree,int offset){
}
}
void destroy_tree(struct tree* tree){
if(tree==NULL) return;
destroy_tree(tree->left);
destroy_tree(tree->right);
free(tree);
}
int main(void)
{
@ -83,10 +94,9 @@ int main(void)
}while(1);
printf("Koniec\n");
destroy_tree(tr);
tr=NULL;
return 0;
}