This is a relatively large project, but I'll try to put all necessary things here.
/** 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());
}
}
This method has an null-pointer error on the parent stuff. I'm not sure how to go about dealing with it.
This is an Ordered Dictionary stored in a BST. Nodes consist of Records which consist of (Key,data) where Key is (name,type). Essentially a Record is ((name,type),data).
I can provide more information if necessary. I've been stuck here for a quite while any help is appreciated!