public class test{
/**
* 求二叉树的深度
* @param t 二叉树
* @return
*/
public static int GetDeep(Tree t){
int l,r;
if(t.equals(null))
return 0;
else{
l=GetDeep(t.left);
r=GetDeep(t.right);
}
if(l>r)
return l+1;
else
return r+1;
}
}
/**
* 二叉树类
* @author Mary
*
*/
class Tree{
int data;
Tree left;
Tree right;
}
求二叉树的深度
最新推荐文章于 2020-10-18 16:42:58 发布