传递指针的内存申请不起作用,要用指针的指针或引用
template<class Object>
void BinaryTree<Object>::create()
{
create(root);
}
template<class Object>
bool BinaryTree<Object>::create(BinaryNode<Object> *&T) //指针申请的内存,所以用指向指针的指针或引用
{
cout << "enter the value of the elem:";
Object x;
cin >> x;
if(x == '#') {T = NULL; delete T;}
else
{
T = new BinaryNode<Object>; //对外不起作用, //指针参数是如何传递内存的。除非使用指向指针的引用
T->elem = x;
create(T->leftChild);
create(T->rightChild);
}
return true;
}