第1个回答 2020-04-08
typedef
struct
bitnode
//二叉树结点定义
{
int
data;
struct
bitnode
*lchild;
struct
bitnode
*rchild;
}bitnode;
bitnode*
binary_create()
//创建二叉树
{
bitnode
*t
=
null;
int
n;
scanf("%d",
&n);
if
(n
!=
0)
{
t
=
(bitnode
*)malloc(sizeof(bitnode));
if
(t
==
null)
printf("内存分配错误!");
else
{
t->data
=
n;
t->lchild
=
binary_create();
t->rchild
=
binary_create();
}
}
return
t;
}
void
binary_output(bitnode
*t)
//前序遍历二叉树
{
if
(t
!=
null)
{
printf("%d
",
t->data);
binary_output(t->lchild);
binary_output(t->rchild);
}
}
void
binary_delete(bitnode
*t)
//释放空间
{
if
(t
!=
null)
{
binary_delete(t->lchild);
binary_delete(t->rchild);
free(t);
}
}
void
inorder(bitnode
*t)
//中序遍历
{
if
(
t
!=
null)
{
inorder(t->lchild);
printf("%d
",
t->data);
inorder(t->rchild);
}
}