#include #include #include #define SIZE 100 struct tree{ char value[SIZE]; struct tree* left; struct tree* right; }; struct tree* read_tree(){ char buffer[SIZE]; memset(buffer,0,SIZE); char* r = fgets(buffer,SIZE,stdin); assert(r); struct tree* node = calloc(1,sizeof(struct tree)); memcpy(node->value,buffer,SIZE); return node; } struct tree* load_tree() { struct tree* node = read_tree(); if (!node) { return NULL; } if (node->value[0] != '*') { node->left = load_tree(); node->right = load_tree(); } return node; } void print_tree(struct tree* tree,int offset){ for (int i = 0; i < offset; i++){ printf(" "); } printf("%s",tree->question); if (tree->left){ print_tree(tree->left,offset +3); print_tree(tree->right,offset +3); } } void destroy_tree(struct tree* tree){ if(tree->left != NULL){ destroy_tree(tree->left); } if(tree->right != NULL){ destroy_tree(tree->right); } free(tree); } void count_items(struct tree* tree, int* count){ if(tree->left == NULL && tree->right == NULL){ (*count)++ }else{ count_items(tree->left, count); count_items(tree->right, count); } }