}
count : maxcount;
return0}
;
//求最低父亲节点(方法一)/* char Parent(Node<Type> *t, char ch1, char ch2) { if (t == NULL)return ‘0‘; else { Parent(t->left, ch1, ch2); Parent(t->right, ch1, ch2); //兴许遍历找近期公共父亲节点。 if (IsHere(t, ch1) == 1 && IsHere(t, ch2) == 1)return t->data; } } *///求最低父亲节点(方法二)char
Parent(Node
<Type>*{
t,char ch1,char ch2)
if(t
!=NULL{
)
stack<Node
<Type>*>st
st;
.push(t);
while(st
.empty()
==false{
)
if(IsHere(t
->left, ch1)
==1&&IsHere(t
->left,ch2)
==1st
{
)
.push(t
->t
left);
=t
->}
continue;
left;
if(IsHere(t
->right, ch1)
==1&&IsHere(t
->right, ch2)
==1st
{
)
.push(t
->t
right);
=t
->}
break;
}
continue;
right;
while(st
.empty()
==falseNode
{
)
<Type>*p
=st
.st
top();
.cout
pop();
<<p
->data<<}
}
endl;
return‘a‘}
;
//查看树中是否有该字符。bool IsHere(Node
<Type>*{
t,char ch)
if(t
==NULL)
returnfalse;
if(t
->data==ch)
returntrue;
else{
if(IsHere(t
->left, ch))
returntrue;
returnIsHere(t
->}
}
right,ch);
//查看指定层的节点个数。int C(Node
<Type>*{
t,int x)
if(x
<1||t
==NULL)
return0;
if(x
==1{
)
return1}
;
elsex
{
--;
returnC(t
->left, x)
+C(t
->}
}
right, x);
//查看叶子节点的个数。来源: http://www.bubuko.com/infodetail-2144593.html