Initializacia
This commit is contained in:
parent
ed75e744fe
commit
822de18141
71
cv7/program.c
Normal file
71
cv7/program.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user