tags:

views:

354

answers:

1
+2  A: 

Your has function should probably look like this:

if (c[val]!=null && word.length()>1) {
    return c[val].has(word.substring(1)); //<-- Change is on this line
} else if (c[val].flag==true && word.length()==1) {
    ...etc

You perform the recursive call, but you really need to let that value propagate back out to the original caller.

Anon.
Wow, that got it. I really need to find some more information on recursion. The only problem now is that I am getting nullpointer exceptions in certain situations.For example:Input the words TEST and TATTER.TEST and TATTER return true, cutting off any characters from those searches return false. This is good. But, if I search for TESTA, I get a nullpointer. Search for TATTERR, I get a nullpointer.I am not sure what is causing this, since I am checking for nulls int he first statement.
dc
Consider the case where `c[val]` is `null` and `word.length()` is 1. `c[val]` is null so the first `if` is false, and we look at the second one. So we test `c[val].flag`... I'm sure you can see the problem.
Anon.
Ah right, so I am checking for the flag of a null value. So simple. A second set of eyes is always so helpful. :)
dc