主题:请问问题出在哪
#include<iostream>
using namespace std;
//二叉树结点
static int count = 0;
template<class T>
struct BinaryTreeNode
{
T data;
BinaryTreeNode<T> * leftChild;
BinaryTreeNode<T> * rightChild;
};
//二叉树,递归法
template<class T>
class BinaryTree
{
public:
BinaryTree(){root = NULL;}
BinaryTree(BinaryTreeNode<T> * root){Create(root);}
~BinaryTree(){Release(root);}
//递归前序遍历
void PreOrder(void (*Operate)(BinaryTreeNode<T>* root),BinaryTreeNode<T> *root);
//递归建立树
void Create(BinaryTreeNode<T> * root);
//递归删除树
void Release(BinaryTreeNode<T>* root);
BinaryTreeNode<T> * root;
//static int count;
};
//前序递归构造树
template<class T>
void BinaryTree<T>::Create(BinaryTreeNode<T>* root)
{
char ch;
cin>>ch;
if(ch == '#')
{
root =NULL;
}
else
{
root = new BinaryTreeNode<T>;
root->data =ch;
Create(root->leftChild);
Create(root->rightChild);
}
}
template<class T>
void Operate(BinaryTreeNode<T>* root)
{
if(root->leftChild ==NULL && root->rightChild ==NULL)
{
count++;
}
}
template<class T>
void BinaryTree<T>::PreOrder(void (*Operate)(BinaryTreeNode<T>* root),BinaryTreeNode<T> *root)
{
if(root)
{
Operate(root);
PreOrder(Operate,root->leftChild );
PreOrder(Operate,root->rightChild );
}
}
template<class T>
void BinaryTree<T>::Release(BinaryTreeNode<T>* root)
{
}
template<class T>
void Output(BinaryTreeNode<T>* root)
{
cout<<root->data;
}
int main()
{
BinaryTreeNode<char> *root= new BinaryTreeNode<char>;
BinaryTree<char> b_Tree(root);
b_Tree.PreOrder (Output,root);
cout<<count<<endl;
return 0;
}
using namespace std;
//二叉树结点
static int count = 0;
template<class T>
struct BinaryTreeNode
{
T data;
BinaryTreeNode<T> * leftChild;
BinaryTreeNode<T> * rightChild;
};
//二叉树,递归法
template<class T>
class BinaryTree
{
public:
BinaryTree(){root = NULL;}
BinaryTree(BinaryTreeNode<T> * root){Create(root);}
~BinaryTree(){Release(root);}
//递归前序遍历
void PreOrder(void (*Operate)(BinaryTreeNode<T>* root),BinaryTreeNode<T> *root);
//递归建立树
void Create(BinaryTreeNode<T> * root);
//递归删除树
void Release(BinaryTreeNode<T>* root);
BinaryTreeNode<T> * root;
//static int count;
};
//前序递归构造树
template<class T>
void BinaryTree<T>::Create(BinaryTreeNode<T>* root)
{
char ch;
cin>>ch;
if(ch == '#')
{
root =NULL;
}
else
{
root = new BinaryTreeNode<T>;
root->data =ch;
Create(root->leftChild);
Create(root->rightChild);
}
}
template<class T>
void Operate(BinaryTreeNode<T>* root)
{
if(root->leftChild ==NULL && root->rightChild ==NULL)
{
count++;
}
}
template<class T>
void BinaryTree<T>::PreOrder(void (*Operate)(BinaryTreeNode<T>* root),BinaryTreeNode<T> *root)
{
if(root)
{
Operate(root);
PreOrder(Operate,root->leftChild );
PreOrder(Operate,root->rightChild );
}
}
template<class T>
void BinaryTree<T>::Release(BinaryTreeNode<T>* root)
{
}
template<class T>
void Output(BinaryTreeNode<T>* root)
{
cout<<root->data;
}
int main()
{
BinaryTreeNode<char> *root= new BinaryTreeNode<char>;
BinaryTree<char> b_Tree(root);
b_Tree.PreOrder (Output,root);
cout<<count<<endl;
return 0;
}