I am trying to read a node that will find the longest word in a tree.
My method is public static int word(Node d)
. So how would I have to find the length of that node? Would I just use the string that was made in the class? The class I would use initializes a boolean, String: theWord and children. Here is what I got:
int newWord = 0;
int word = d.theWord.length();
if (d.isWord) {
if (word > newWord) {
newWord = word;
return longestWord((DTN) d.children);
} else {
return longestWord((DTN) d.children);
}
}
return newWord;