请教关于用C++递归创建二叉树的问题

来源:百度知道 编辑:UC知道 时间:2024/06/10 22:00:27
编译环境VC++6.0

要求:
1用结构体定义结点
2在类中用成员函数递归创建树的结点(空格表示空树)

下面是我写的代码 提示说转换类型失败
请问问题在哪?或者格式应该怎么写才是正确的?

代码如下:

//version 1.0(081204)

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

struct BiTreeNode
{
char data;
struct BiTreeNode *rchild,*lchild;
};

class BiTree
{
public:
void Create(struct BiTreeNode *);
void Display();
};

void BiTree::Create(struct BiTreeNode *Tnode)
{
char ch;
cin>>ch;
if(ch==" ")//空格表示空树
{
Tnode=NULL;
}
else
{
Tnode=(struct BiTreeNode *)malloc(sizeof(struct BiTreeNode));
Tnode->data=ch;
Create(Tnode->lchild);
Create(Tnode->rchild);
}
cout<<"Create Complated!"<<endl;
}

int main()
{

struct BiTreeNode *Tnode;
BiT

#include <iostream>
#include <stdlib.h>
using namespace std;
struct BiTreeNode
{
char data;
struct BiTreeNode *rchild,*lchild;
};

class BiTree
{
public:
void Create(struct BiTreeNode *);
void Display();
};

void BiTree::Create(struct BiTreeNode *Tnode)
{
char ch;
cin>>ch;
if(ch==' ')//空格表示空树
{
Tnode=NULL;
}
else
{
Tnode=(struct BiTreeNode *)malloc(sizeof(struct BiTreeNode));
Tnode->data=ch;
Create(Tnode->lchild);
Create(Tnode->rchild);
}
cout<<"Create Complated!"<<endl;
}

int main()
{

struct BiTreeNode *Tnode;
BiTree BT1;
BT1.Create(Tnode);
return 0;
}

二叉树的类定义和实现
//btree.h//
tepmplate<class T>class BTree{
private:
BTree<T> *left;
BTree<