求一段简单的建立二叉树的C++代码!

2025-04-14 22:11:34
推荐回答(1个)
回答(1):

/*---二叉树的建立---*/
BTNode *createbintree()
{
BTNode *t;
char x;
scanf("%c",&x);
if (x=='#') t=NULL;
else
{
t=(BTNode *)malloc(sizeof(BTNode));
t->data=x;
t->lchild=createbintree();
t->rchild=createbintree();
}
return(t);
}