[Java Help] will provide porn if solved

Mafo

Veteran X
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
Code:
System.out.println("minimum(current.right.entry.word): " + minimum(current.right.entry.word));
I get the proper result of: minimum(current.right.entry.word): abaciscus

but when I do
Code:
return minimum(current.right.entry.word);
from
Code:
success.entry.word = successor(current.entry.word);
i get an error:
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
 
notice that i've done a lot of the homework dumbass
believe it or not this is one part of a bigger assignment
if i had asked for the assignment to be done then you wouldn't look like such a fuck but i guess it's too late

as for the porn, TW tends to crave it
 
Maybe it's time for you to consider a business degree?


On a side note: Do you even know what a null pointer exception is?
 
i love business
but right now im in CS
and i know what a null pointer is, but clearly i dont know why im getting it
 
I don't know all too much about java (little experience), but I was just going to play around with it in textpad until it worked. However, I can't do that without the whole class, so sorry buddy :(.

edit: nvm

double edit: yeah don't have all the classes (dictionary exception, orderedDictionaryADT, Node) no go.
 
Last edited:
I think it has something to do with the successor Node not ready to handle a string, but i've tried everything i can thnk of and it still won't budge
 
it doesn't make sense, I have
Code:
String crazy = successor(current.entry.word);
coming from
Code:
public String successor(String word)

it's returning a string and im assigning the return value to a string
WTF :/
 
Not really reading much of the code, have you thought about modifying some of your methods to return NEW string(oldreturnvalue) or perhaps throw the return value into a new string such as foo = new string(method(x));

Somewhere in there, you're returning a null pointer. Since it appears to be printing correctly inside the method, the issue is probably related to when you pass it back out of the method.
 
it doesn't make sense, I have
Code:
String crazy = successor(current.entry.word);
coming from
Code:
public String successor(String word)

it's returning a string and im assigning the return value to a string
WTF :/

dude, string crazy = NEW string(other shit)

edit:

String crazy = new String(successor(current.entry.word));
 
Back
Top