-1
這是一個相對較大的項目,但我會盡力在這裏提供所有必要的東西。無法從BST中刪除
/** Removes the record with Key k from the dictionary. It throws a
DictionaryException if the record is not in the dictionary. */
public void remove(Key k) throws DictionaryException{
deleteNode = findNode(k);
if (deleteNode == null) throw new DictionaryException("Error: Record doesn't exist in the dictionary!");
else{
//check if children are leafs
if(deleteNode.getLeftChild() == null || deleteNode.getRightChild() == null)
//set it to itself
replace = deleteNode;
else
//otherwise replace with successorNode
replace = successorNode(deleteNode);
//store left child if it exists
if (replace.getLeftChild() != null)
child = replace.getLeftChild();
//else, store right
else
child = replace.getRightChild();
//check if both nodes are null
if (child != null)
child.setParent(replace.getParent());
//else replace the node that needs to be deleted
else{
//replace left child of parent
if(replace == replace.getParent().getLeftChild())
replace.getParent().setLeftChild(child);
//else replace right
else
replace.getParent().setRightChild(child);
}
//store information of the replacing node, within the deleteNode
if (replace != deleteNode)
deleteNode.setRoot(replace.getRecord());
}
}
此方法在父項目上有一個空指針錯誤。 我不知道如何去處理它。
這是存儲在BST中的有序字典。節點由包含(密鑰,數據)的記錄組成,其中密鑰是(名稱,類型)。本質上記錄是((姓名,類型),數據)。
如有必要,我可以提供更多信息。我一直在這裏呆了一段時間,任何幫助表示讚賞!
歡迎堆棧溢出!它看起來像你需要學習使用調試器。請幫助一些[互補調試技術](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果您之後仍然有問題,請隨時返回更多詳情。 –