Update cv7/program.c
This commit is contained in:
parent
9acb88877a
commit
3043acee18
@ -16,24 +16,28 @@ struct tree
|
|||||||
struct tree *left, *right;
|
struct tree *left, *right;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tree* read_tree(struct tree* p)
|
struct tree* read_tree()
|
||||||
{
|
{
|
||||||
char buffer[SIZE];
|
char buffer[SIZE];
|
||||||
memset(buffer,0,SIZE);
|
memset(buffer,0,SIZE);
|
||||||
char* r = fgets(buffer,SIZE,stdin);
|
char* r = fgets(buffer,SIZE,stdin);
|
||||||
|
|
||||||
assert(r);
|
assert(r);
|
||||||
struct tree* node = (struct tree*)calloc(1,sizeof(struct tree));
|
struct tree* node = (struct tree*)calloc(1,sizeof(struct tree));
|
||||||
memcpy(node->value,buffer,SIZE);
|
memcpy(node->value,buffer,SIZE);
|
||||||
//printf("\n%s", node->value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
node->left=NULL;
|
node->left=NULL;
|
||||||
node->right=NULL;
|
node->right=NULL;
|
||||||
|
|
||||||
if(node->value[0]!='*')
|
if(node->value[0]!='*')
|
||||||
{
|
{
|
||||||
|
|
||||||
read_tree(node->left);
|
node->left=read_tree(node->left);
|
||||||
|
|
||||||
read_tree(node->right);
|
node->right=read_tree(node->right);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -44,7 +48,8 @@ void print_tree(struct tree* tree,int offset){
|
|||||||
printf(".");
|
printf(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("(%s)",tree->value);
|
if(tree)
|
||||||
|
printf("%s",tree->value);
|
||||||
if (tree->left){
|
if (tree->left){
|
||||||
print_tree(tree->left,offset +3);
|
print_tree(tree->left,offset +3);
|
||||||
}
|
}
|
||||||
@ -59,8 +64,9 @@ int main(void)
|
|||||||
|
|
||||||
struct tree *tr;
|
struct tree *tr;
|
||||||
|
|
||||||
read_tree(tr);
|
tr=read_tree();
|
||||||
printf("-------");
|
|
||||||
print_tree(tr,3);
|
print_tree(tr,3);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user