#include #include #include #include #define SIZE 100 struct tree { char* value; struct tree* left; struct tree* right; }; struct tree* read_tree(){ char buffer[SIZE]; memset(buffer, 0, SIZE); char* r = fgets(buffer, SIZE, stdin); if(buffer[0] == '\n'){ return NULL; } assert(r); struct tree* node = calloc(1, sizeof(struct tree)); node->value = malloc(strlen(buffer) + 1); assert(node->value); node->left = read_tree(); node->right = read_tree(); return node; } void destroy_tree(struct tree* node) { if (node == NULL) return; destroy_tree(node->left); destroy_tree(node->right); free(node); } int main(){ struct tree* root = read_tree(); read_tree(); destroy_tree(root); return 0; }