为什么我用先建立的二叉树,递归调用结束不了??????
代码如下
Bitree CreatTree(Bitree &T)二叉树 递归 c C++ 算法
{
Elem ch;
cout<<"enter the data: \n";
cin>>ch;
if(ch=='#')
T = NULL;
else
{
T->data = ch;
CreatTree(T->lch);
CreatTree(T->rch);
}
return T;
}
#include<iostream>
//#include<stdlib.h>
using namespace std;
typedef char Elem;
typedef struct TNode{
Elem data;//数据域
struct TNode *lch,*rch;//左右孩子指针
}TNode,*Bitree;
Bitree CreatTree(Bitree T)
{
Elem ch;
cout<<"enter the data: \n";
cin>>ch;
if(ch=='#')
T = NULL;
else
{
T->data = ch;
T->lch=(Bitree)malloc(sizeof(TNode));
CreatTree(T->lch);
T->rch=(Bitree)malloc(sizeof(TNode));
CreatTree(T->rch);
}
return T;
}
int main(){
TNode T;
CreatTree(&T);
return 0;
}