二叉树的建立为什么编译没有错误,但是不出结果?

论坛 期权论坛 期权     
匿名   2018-10-21 04:53   3992   1
#includeusingnamespacestd;typedefstructbitree{chardata;bitree*lchild;bitree*rchild;}bitree;voidcreate(bitree*root){charch;cin>>ch;if(ch=='.')root=NULL;else{bitr...#include
using namespace std;
typedef struct bitree
{
char data;
bitree * lchild;
bitree * rchild;
}bitree;
void create(bitree *root)
{
char ch;
cin>>ch;
if(ch=='.') root=NULL;
else
{
  bitree *root=new bitree;
  root->data=ch;
  create(root->lchild);
  create(root->rchild);
}
}
void preorder(bitree *root)
{
if(root!=NULL)
{
  coutlchild);
  preorder(root->rchild);
}
}

int main()
{
bitree * root;
create(root);
preorder(root);
prebitree(root);
return 0;
}
分享到 :
0 人收藏

1 个回复

倒序浏览
bitree *root=new bitree 可以有问题,它又声明了一个新局部变量
另外只有内存申请,没有释放,有可能会有问题
还有prebitree定义在哪里
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:58388
帖子:6688
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP