树的创建

#include <iostream>
#include <malloc.h>
using namespace std;
typedef int ElementType;
typedef struct tree{
char data;
struct tree *lchild,*rchild;
}Tree;
void CreatBTree(Tree *&T){
T=new Tree;
T->lchild=NULL;
T->rchild=NULL;
char data;
cin>>data;
if(data=='#'){
T=NULL;
return;
}
else
{
T->data=data;
}
CreatBTree(T->lchild);
CreatBTree(T->rchild);
}
int main(){
Tree *T;
cout<<"创建二叉树序列:"<<endl;
CreatBTree(T);
return 0;

}

posted @ 2019-04-30 08:52  罗小赐  阅读(256)  评论(0编辑  收藏  举报