-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/)을 참고하십시오. 나중에 문제가 계속되는 경우 자세한 내용을 알려 주시기 바랍니다. –