二叉树的前序创建问题的求助
我的代码如下:(我估计我是逻辑上的错误,请大家指教啊)(用C++写的)#include"iostream.h"
#include"stdlib.h"
#include"stdio.h"
struct btree
{
char c;
btree *left;
btree *right;
};
btree *b=NULL;
void create(btree *p)
{
if(p==NULL)
{
char m;
cout<<"输入一个字符:";
cin>>m;
cout<<endl;
if(m!='#')
{
p=new (btree);
p->c=m;
p->left=NULL;
p->right=NULL;
create(p->left);
create(p->right);
}
}
}
void print(btree *p)
{
if(p!=NULL)
{
cout<<p->c<<" ";
print(p->left);
print(p->right);
}
}
int main()
{
create(b);
print(b);
return 0;
}