二叉树(C++)的简单问题,希望那位朋友能帮忙细说一下,酌情另加分!

来源:百度知道 编辑:UC知道 时间:2024/06/05 04:55:37
下面是我定义的一个二叉树类,我的问题在最下面的main()函数里面
//二叉树类
#include<iostream>
using namespace std;
template<class T>class BinaryTreeNode;
template<class T>//class BinaryTree;
class BinaryTree{
private:
BinaryTreeNode<T>* root;
BinaryTreeNode<T>* current;
public:
BinaryTree()
{
root=0;
}
BinaryTree<T>(T data ,BinaryTree<T>& ltree,BinaryTree<T>& rtree)
{
root=new BinaryTreeNode<T>(T data,ltree.root,rtree.root)
ltree=0;
rtree=0;
}
T getRightchild()
{
BinaryTreeNode* p;
p=root;
return p->right->getValue();
}
~BinaryTree<T>()
{
deleteBinaryTreeNode(root);
}
deleteBinaryTree(BinaryTreeNode* root)
{
if(root)
{
deleteBinaryTree(root->leftchild);//递归不怎么懂
deleteBinaryTree(root->rightchild);

你这样的写法只能在定义对象的语句里面来用的,因为其相当于调用了构造函数,不能当作普通函数来使用。

T1(1),T2(2)
T(1,T(1),T(2));

T(1,B1(2),B2(3))
你这样的写法只能在定义对象的语句里面来用的,因为其相当于调用了构造函数,不能当作普通函数来使用。