package cn.edu.besti.cs1923.G2311;
public class BinaryTreeNode {
protected T element;
protected BinaryTreeNode left;
protected BinaryTreeNode right;
public BinaryTreeNode(T obj) {
this.element = obj;
this.left = null;
this.right = null;
}
///合并构建声明
public BinaryTreeNode(T obj, LinkedBinaryTree left,
LinkedBinaryTree right)throws EmptyCollectionException {
element = obj;
if (left == null)
this.left = null;
else
this.left = left.getRootNode();
if (right == null)
this.right = null;
else
this.right = right.getRootNode();
}
public int numChildren() {
int children = 0;
if (left != null)
children = 1 + left.numChildren();
if (right != null)
children = children + 1 + right.numChildren();
return children;
}
public T getElement() {
return element;
}
public BinaryTreeNode getRight() {
return right;
}
public void setRight(BinaryTreeNode node) {
right = node;
}
public BinaryTreeNode getLeft() {
return left;
}
public void setLeft(BinaryTreeNode node) {
left = node;
}
public boolean judge(){
if(right == null && left == null)
return true;
else
return false;
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史