[题目分析] 由于以双亲表示法作树的存储结构找结点的双亲容易因此我们可求出每一结点的层次取其最大层次就是树有深度对每一结点找其双亲双亲的双亲直至(根)结点双亲为为止
int Depth(Ptree t) //求以双亲表示法为存储结构的树的深度Ptree的定义参看教材
{int maxdepth=;
for(i=;i<=tn;i++)
{temp=; f=i;
while(f>) {temp++; f=tnodes[f]parent; } // 深度加并取新的双亲
if(temp>maxdepth) maxdepth=temp; //最大深度更新
}
return(maxdepth);//返回树的深度
} //结束Depth
[题目分析] 二叉树是递归定义的其运算最好采取递归方式
int Height(btre bt)//求二叉树bt的深度
{int hlhr;
if (bt==null) return();
else {hl=Height(bt>lch); hr=Height(bt>rch);
if(hl>hr) return (hl+); else return(hr+);
} }
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []