猿问

我的这个 为什么无法输出?

#include<iostream>
using namespace std;
struct BTnode
{
 int data;
 BTnode *Lchild,*Rchild;
};
class Tree
{
private:
 BTnode *m_root;
public:
 Tree();
 ~Tree();
 void creat(int *ch,const int c);
 void _creat(BTnode *T,int &i,int *ch,const int c);
 void _PerTraverse(BTnode *T);
 void PerTraverse();

};
Tree::~Tree()
{
 delete m_root;
}
Tree::Tree()
{
   m_root=NULL;
}
//先序遍历
void Tree::PerTraverse()
{
 _PerTraverse(m_root);
}
void Tree::_PerTraverse(BTnode *T)
{
 if(T)
 {
  
  cout<<T->data<<" ";
  _PerTraverse(T->Lchild);
 
  _PerTraverse(T->Rchild);
  
 }


}
//先序
void Tree::creat(int *ch,const int c)
{
 int i=0;
 _creat(m_root,i,ch,c);
 
}
void Tree::_creat(BTnode *T,int &i,int *ch,const int c)
{
 
 if(ch[i]==c)
   T=NULL;
 else
 {
  T=new BTnode;
  T->data=ch[i];
  _creat(T->Lchild,++i,ch,c);
  _creat(T->Rchild,++i,ch,c);
 }


}

void main()
{

 int a[100]={1,2,4,0,0,5,7,0,8,0,0,0,3,6,0,0,0};
    int c=0;
 Tree t;
 t.creat(a,c);
 t.PerTraverse();
}


慕田峪7551596
浏览 1135回答 0
0回答
随时随地看视频慕课网APP
我要回答