二叉树有问题 请我看一看
#include "stdafx.h "
#include "iostream.h "
#include "malloc.h "
typedef struct node
{
char data;
struct node *lchild ,*rchild;
}bitree;bitree *p;
bitree * Creat_bitree(bitree *root,char c)
{
char ch[]={ "abc$$de$gf$$$ "};
cout < < "creat " < <endl;
if(ch[c]!= '$ ')
{
root=(bitree*)malloc(sizeof(bitree));
root-> data=ch[c];
c++;
Creat_bitree(root-> lchild,c);
Creat_bitree(root-> rchild,c);
}
else
root=NULL;
return root;
}
void DFS(bitree *p)
{
if(!p)
return ;
cout < <p-> data < <endl;
DFS(p-> lchild);
DFS(p-> rchild);
cout < < "shf " < <endl;
}
void main( )
{
bitree *root,*p;
//char ch[]={ "a,b,c,$,d,e,$,f,$,$ "};
//for(int i=0;i <11;i++)
p=Creat_bitree(root,0);
DFS(p);
cout < < "shdw " < <endl;
}
[解决办法]
bitree * Creat_bitree(bitree * &root,char c)
[解决办法]
第一:node节点类没有构造函数。
第二:更严重的错误,左右指针指向谁?