Alright, I have no clue why this won't work. Basically, I have 3 methods working right now, remove() which ends up calling successor() which ends up calling minimum(). If anyone is familiar with Binary Search Trees then you could probably help.
Basically when successor() calls minimum(), the value returned is a String. minimum() is given a string, finds it, then finds the minimum value in that Strings tree.
When I do a
I get the proper result of: minimum(current.right.entry.word): abaciscus
but when I do
from
i get an error:
success.entry.word and current.entry.word are both string values, and the methods return and ask for strings appropriately, so i have no clue why i can't assign this string to a string variable...
incase you want all the code...
soemone help a brother out and ill provide a nice 200-300MB porn on DH hosting for you all
Basically when successor() calls minimum(), the value returned is a String. minimum() is given a string, finds it, then finds the minimum value in that Strings tree.
When I do a
Code:
System.out.println("minimum(current.right.entry.word): " + minimum(current.right.entry.word));
but when I do
Code:
return minimum(current.right.entry.word);
Code:
success.entry.word = successor(current.entry.word);
Code:
Exception in thread "main" java.lang.NullPointerException
at OrderedDictionary.successor(OrderedDictionary.java:154)
at OrderedDictionary.remove(OrderedDictionary.java:129)
at Query.main(Query.java:42)
success.entry.word and current.entry.word are both string values, and the methods return and ask for strings appropriately, so i have no clue why i can't assign this string to a string variable...
incase you want all the code...
Code:
else { // two children, so replace with inorder successor
// get successor of node to delete (current)
DictEntry fill = new DictEntry("hello", "filler");
Node success = new Node(fill);
[b]success.entry.word = successor(current.entry.word);[/b]
find(word);
// connect parent of current to successor instead
if(current == root) {
root = success;
}
else if(isLeftChild) {
parent.left = success;
}
else {
parent.right = success;
}
// connect successor to current's left child
success.left = current.left;
} // end else two children
}
public String successor(String word) {
find(word);
Node successor = new Node();
if (current.right != null) {
System.out.println("minimum(current.right.entry.word): " + minimum(current.right.entry.word));
return minimum(current.right.entry.word);
}
else {
System.out.println("No Need for minimum of: " + current.right.entry.word);
successor = current.parent;
while ((successor != null) && (current == successor.right)) {
current = current.parent;
successor = successor.parent;
}
return successor.entry.word;
}
}
private String minimum(String word) {
System.out.println("Current: " + current.entry.word);
while (current.left != null) {
System.out.println("Current: " + current.entry.word);
current = current.left;
}
System.out.println("FINAL WORD: " + current.entry.word);
return current.entry.word;
}
soemone help a brother out and ill provide a nice 200-300MB porn on DH hosting for you all