template<class T>
BiTreeNode<T>* getTreeNode(Titem,
BiTreeNode<T> *left = NULL,
BiTreeNode<T>* right = NULL)
{
BiTreeNode<T>* p;
p = new BiTreeNode<T>(item,left,right);
if(p == NULL)
{
cerr << "内存分配失败!\n";
exit(1);
}
return p;
}
template<class T>
BiTreeNode<T>* CreateBiTree( )
{
BiTreeNode<T>* t;
char ch;
scanf("%c",&ch);
if(ch!='#')
{
t=getTreeNode(ch);
t->left()= CreateBiTree( );
t->right()= CreateBiTree( );
}
else
t=NULL;
return t;
}
BiTreeNode<T>* getTreeNode(Titem,
BiTreeNode<T> *left = NULL,
BiTreeNode<T>* right = NULL)
{
BiTreeNode<T>* p;
p = new BiTreeNode<T>(item,left,right);
if(p == NULL)
{
cerr << "内存分配失败!\n";
exit(1);
}
return p;
}
template<class T>
BiTreeNode<T>* CreateBiTree( )
{
BiTreeNode<T>* t;
char ch;
scanf("%c",&ch);
if(ch!='#')
{
t=getTreeNode(ch);
t->left()= CreateBiTree( );
t->right()= CreateBiTree( );
}
else
t=NULL;
return t;
}