代码仅供参考(手动滑稽)
#include <iostream>
using namespace std;
typedef struct BitNode{
char data;
BitNode *lchild;
BitNode *rchild;
}BitNode;
class bitt{
private:
BitNode * bt;
void create(BitNode *&t) ;
int countleaf(BitNode *t);
int counthigh(BitNode *t);
BitNode *search(BitNode *t,char x);
public:
void recreate();
int countleafbit();
int counthighbit();
BitNode *search();
};
void bitt::create(BitNode *&t){
char ch;
cin >> ch;
if (ch == '.') t = NULL;//是否等于空树
else{
t = new BitNode;
t->data = ch;
create(t->lchild);
create(t->rchild); //递归输入
}
}//创建二叉树
void bitt::recreate(){
BitNode *t;
create(t);
bt = t;
}
int bitt::countleafbit(){
BitNode *t = bt; //保护私有成员
return countleaf(t);
}
int bitt::countleaf(BitNode *t){
if(t == NULL)return 0;
else{
int m = countleaf(t->lchild);
int n = countleaf(t->rchild);
if(m+n==0)return 1;
else return m+n;
}
}
int bitt :: counthigh(BitNode *t){
if(t == NULL)return 0;
else{
int m = 1 + counthigh(t->lchild);
int n = 1 + counthigh(t->rchild);
if (m >= n )return m;
else n;
}
int bit::counthighbit(){
BitNode *t = bt;
return countleaf(t);
}
}
BitNode* bitt::search(BitNode *t,char x){
if (t== NULL)return t;
else {
if (t->data == x) return t;
BitNode *p = search(t->lchild,x);
if(p)return p;
return search(t->rchild ,x);
}
}
BitNode * bitt :: searchbit(char x){
BitNode *t = bt;
return search(t , x);
}
//iiiiiiiiiii
int countone(bitnode *t){
if(!t)return 0;
if(t->lchild && !t->rchild == 0 || !t->lchild && t->rchild)return 1 + countone(t->child)+counto(t->rchild);
else return countone(t->child)+counto(t->rchild) ;
}
//计算结点数量
//判定两个二叉树是否相识
//形式相同,长的一样,节点的值不一样
//相似返回1,否则返回0
int alike(bitnode *t,bitnode *s){
if(!t && !s)return 1;
if(t && !s || !t && s)return 0;
else return alike(t->lchild , s->lchild) && alike(t->rchild , s->rchild)
}
//
int main(){
bitt bbt;
bbt.recreate();
cout << bbt.countleafbit << endl;
cout << bbt.search('a')->data << endl;
}