二叉树的中序建立???

来源:百度知道 编辑:UC知道 时间:2024/06/29 02:57:10
先序建立的算法如下:
BitTree PreCreatBitTree (void)
{
BitTree bt;
char ch;
cin>>ch;
if (ch=='#')
return NULL;
else
{
if (!(bt=(BitTree)malloc(sizeof(BitNode)))) return NULL;
bt->data=ch;
bt->lc=PreCreatBitTree();
bt->rc=PreCreatBitTree();
}
return bt;
}
哪位讲一下中序建立的?

同楼上的~~~~~其实它访问每个结点的次序是一样的。只是什么时候对某个结点的操作不一样而已!

BitTree PreCreatBitTree (void)
{
BitTree bt;
char ch;
cin>>ch;
if (ch=='#')
return NULL;
else
{
if (!(bt=(BitTree)malloc(sizeof(BitNode)))) return NULL;
bt->lc=PreCreatBitTree();
bt->data=ch; //把这句放到中间就行了,因为函数的递归调用的..
bt->rc=PreCreatBitTree();
}
return bt;
}