【发布时间】:2015-11-21 22:10:15
【问题描述】:
我正在尝试使用递归来为 BST 编写插入方法。
public void insert(DictEntry data) throws BSTException {
if (find(data.getPosition()) == data){
throw new BSTException();
}
else {
if (current == null){
root.setRoot(data);
}
else {
while(current != null){
if (data.getPosition().compareTo(root.getRoot().getPosition()) < 0){
current = current.getLeft();
}
else{
if (data.getPosition().compareTo(root.getRoot().getPosition()) > 0){
current = current.getRight();
}
else
;
}
insert(data);
}
}
}
}
但我不知道由于某种原因测试用例总是失败。 有人可以帮我解决吗?
【问题讨论】:
标签: java insert binary-search-tree