usaa24/cv7/program.c

72 lines
1.4 KiB
C
Raw Normal View History

2024-11-09 21:40:16 +00:00
#include<stdio.h>
#include<string.h>
#include<assert.h>
#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 tstruct tree* load_tree() {
struct tree* tree = read_tree();
tree->left = load_tree();
tree->right = load_tree();
if (tree->value[0] == "*"){
re
}
}
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);
}
}
int main() {
printf("Constructing the tree:\n");
struct tree* root = test();
printf("The tree structure:\n");
print_tree(root, 0);
return 0;
}