public void postOrder(){//后根次序遍历二叉树
System.out.print("\n后根序列: ");
postOrder(root);
}
private void postOrder(BinaryNode<E> p){//后根次序遍历以p结点为根的子树
if(p != null){//若二叉树不空
postOrder(p.left);//访问根次序遍历当前结点的左子树
postOrder(p.right);//访问根次序遍历当前结点的右子树
System.out.print(p.data + " ");//访问当前结点
}
}
//求结点个数
public int count(){//返回二叉树的结点个数
return count(root);
}
private int count(BinaryNode<E> p){//返回以p结点为根的子树的结点个数
if(p != null)
return 1 + count(p.left) + count(p.right);
else
return 0;
}
//求高度
public int height(){//返回二叉树的高度
return height(root);
}
private int height(BinaryNode<E> p){//返回以p结点为根的子树高度,后根次序遍历