[c]代码库
void CreateBinTree ( BinTree *T )
{/*以加入结点的先序序列输入,构造二叉链表*/
char ch;
scanf ( "\n%c",&ch );
if ( ch=='0' ) *T=NULL; /*读入0 时,将相应结点置空*/
else
{
*T= ( BinTNode* ) malloc ( sizeof ( BinTNode ) ); /*生成结点空间*/
( *T )->data=ch;
CreateBinTree ( & ( *T )->lchild ); /*构造二叉树的左子树*/
CreateBinTree ( & ( *T )->rchild ); /*构造二叉树的右子树*/
}
}
void InOrderOut ( BinTree T )
{/*中序遍历输出二叉树T 的结点值*/
if ( T )
{
InOrderOut ( T->lchild ); /*中序遍历二叉树的左子树*/
printf ( "%3c",T->data ); /*访问结点的数据*/
InOrderOut ( T->rchild ); /*中序遍历二叉树的右子树*/
}
}
main()
{
BiTree bt;
CreateBinTree ( &bt );
InOrderOut ( bt );
}