#includeiostream
using namespace std;
运用递归思维求解二叉树遍历问题(个别考虑并写高难度的)//能很好地了解递归思想
typedef struct xx
{
int age;
xx* lchild;
xx* rchild;
}tree,* bitree;
(bitreet,bitree newt ) )。
{
if(t==null ) )。
{
返回;
}
else
{
newt=new xx;
newt-age=t-age;
复印(t-lchild,newt-lchild );
复制(t-rchild,newt-rchild );
}
将//t树复制到newt树//newt树=t树
intdepth(bitreet )。
{
int m,n;
if(t==null ) )。
{
返回0;
}
else {
m=Depth(t-Lchild );
n=Depth(t-Lchild );
return m n? m 1: n 1; //三目运算符
}
//求深()递归思想)哪里深
intnodnum(bitreet )。
{
if(t==null ) )。
{
返回0;
}
else
returnnodnum(t-lchild ) nod num (t-rchild ) 1; //1加上根节点
//求出节点的总数//按节点遍历(递归思想) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) 652 )
输入长度(bitreet ) )。
{
if(t==null ) )。
{
返回0; //不存在直接向根节点返回0的内容
}
if (t-lchild==nullt-rchild==null ) () ) ) ) ) ) )。
{
返回1; //只有根节点返回1
}
else
{
返回长度(t-rchild )长度(t-rchild );
(//递归地按叶的每个节点求出)当一个节点左右都为NULL时返回1,依次递归地相加) ) )。
//求出叶的节点数(递归思想) ) )
int main () )
{
返回0;
}