【发布时间】:2014-10-12 22:06:38
【问题描述】:
当我没有被传递一个节点时,我目前在理解如何从二叉搜索树中删除一个节点时遇到问题。我有 2 个类,BSTSet 和 BSTNode,每个类都有一个 remove 方法..
public class BSTSet <E extends Comparable<E>> extends AbstractSet <E> {
// the root of the supporting binary search tree
private BSTNode<E> root;
// number of elements in the set
private int count = 0;
public boolean remove(E item) {
if(root == null) return false;
else return root.remove(item);
}
}
public class BSTNode <E extends Comparable<E>> {
private E value;
private BSTNode<E> left;
public BSTNode<E> right;
public BSTNode<E>remove(E item) {
//The code i'm confused about
}
}
当我被传递一个节点时,我了解删除方法,但是当我在根上调用 remove 方法并尝试从 Node 类中删除节点时,我不知道从哪里开始。有人可以启发我吗?谢谢。如果您想了解更多信息,请询问。
【问题讨论】: