1. 二叉树的深度
public int getDepth() {
if((lchild == null)&&(rchild == null)) {
return 1;
}
int lDepth = 0;
if(lchild != null) {
lDepth = lchild.getDepth();
}
int rDepth = 0;
if(rchild != null) {
rDepth = rchild.getDepth();
}
if(lDepth >= rDepth) {
return lDepth+1;
}
else {
return rDepth+1;
}
}
2. 二叉树的节点数
public int getNodeNum() {
if((lchild == null)&&(rchild == null)) {
return 1;
}
int lNode = 0;
if(lchild != null) {
lNode = lchild.getNodeNum();
}
int rNode = 0;
if(rchild != null) {
rNode = rchild.getNodeNum();
}
return lNode+rNode+1;
}
3. 是否是左节点
在这里插入代码片
4. 获得元素下标
5. 是否为空