自己写了一个程序,是求二叉树结点个数,打印叶子结点,求二叉树深度,后序的逆序遍历。程序有错,请大虾帮我看看(有颜色标注的是有提示错误的地方):
//newBiTree.h
#ifndef NEWBITREE_H
#define NEWBITREE_H
template<class T>
struct BiNode
{
 BiNode<T> *lchild,*rchild;
 T data;
};
template<class T>
class newBiTree
{
 public:
  newBiTree();    //构造函数,初始化一棵二叉树
  ~newBiTree(void);  //析构函数
  BiNode<T> * Getroot();  //获得指向根结点的指针
  void Count(BiNode * root);   //求二叉树结点个数
  void PreOrder(BiNode * root);  //打印叶子结点
     int Depth(BiNode * root);   //求二叉树的深度
  void PostOrder(BiNode * root);  //后序的逆序遍历输出
 private:
  BiNode<T> * root;  //指向根结点的头指针
  BiNode<T> * Creat();  //有参构造函数调用
  void Release(BiNode<T> *root);  //析构函数调用
};
#endif
//newBiTree.cpp
#include<iostream>
#include"newBiTree.h"
#include<string>
using namespace std;
#define int n=0;
template<class T>
newBiTree<T>::newBiTree()  //构造函数
{
 this->root=Creat();
}
template<class T>
newBiTree<T>::~newBiTree(void)  //析构函数
{
 Release(root);
}
template<class T>
BiNode<T> * newBiTree<T>::Getroot()
{
 return root;
}
template<class T>
BiNode<T> * newBiTree<T>::Creat()
{
 BiNode<T> * root;
 T ch;
 cout<<"请输入创建一棵二叉树的结点数据"<<endl;
 cin>>ch;
 if(ch=="#")root=NULL;
 else{
  root=new BiNode<T>;
  root->data=ch;
  root->lchild=Creat();
  root->rchild=Creat();
 }
 return root;
}
template<class T>
void newBiTree<T>::Release(BiNode<T> *root)   
{
 if(root!=NULL){
  Release(root->lchild);
  Release(root->rchild);
  delete root;
 }
}
template<class T>
void newBiTree<T>::Count(BiNode<T> *root)
{
 if(root){
  Count(root->lchild);
  n++;
  Count(root->rchild);
 }
}
template<class T>
void newBiTree<T>::PreOrder(BiNode<T> *root)
{
 if(root){
  if(!root->lchild&&!root->rchild)cout<<root->data;
  PreOrder(root->lchild);
  PreOrder(root->rchild);
 }
}
template<class T>
T newBiTree<T>::Depth(BiNode<T> *root)
{
 if(!root) return 0;
 BiNode<T>* hl;
 BiNode<T>* hr;
 else{
  hl=Depth(root->lchild);
  hr=Depth(root->rchild);
  return ((hl>hr)?(hl+1):(hr+1));
 }
}
template<class T>
void newBiTree<T>::PostOrder(BiNode<T> *root)
{
 cout<<root->data;
 PostOrder(root->rchild);
 PostOrder(root->lchild);
}
//newBiTreeMain.cpp
#include<iostream>
#include<string>
#include"newBiTree.cpp"
using namespace std;
void main()
{
 newBiTree<string> bt;
 BiNode<string>* root=bt.Getroot();
 cout<<"二叉树结点数为:"<<endl;
 bt.Count(root);
 cout<<endl;
 cout<<"叶子结点为:"<<endl;
 bt.PreOrder(root);
 cout<<endl;
 cout<<"二叉树深度为:"<<endl;
 bt.Depth(root);
 cout<<endl;
 cout<<"后序的逆序为:"<<endl;
 bt.PostOrder(root);
 cout<<endl;
}



											
	    

	
