首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

二叉树有有关问题 请小弟我看一看

2012-02-06 
二叉树有问题 请我看一看#includestdafx.h #includeiostream.h #includemalloc.h typedefstructnode

二叉树有问题 请我看一看
#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节点类没有构造函数。
第二:更严重的错误,左右指针指向谁?

热点排行