public class WordTreeNode *Highest allowable character index is NUMCHILDREN-1 (a
ID: 3606229 • Letter: P
Question
public class WordTreeNode *Highest allowable character index is NUMCHILDREN-1 (assuming one-byte ASCII i.e. "extended ASCII") NUMCHILDREN is constant (static and final) To access it, write *"TreeNode.NUMCHILDREN For simplicity, we have given each WordTree node 256 children. Note that if our words only consisted of characters from (a,z,A,) then we would only need 52 children. The WordTree can represent more " general words e.g. it could also represent many special characters often used in passwords. public static final int NUCHILDREN-256; WordTreeNode parent; WordTreeNode[] children; int depth; // for root, 1 for root's children, 2 for their children, // etc.. char charInParent; I/ Character associated with the tree edge from this // node's parent // to this node. // See comment above for relationship between an index in // char value. to 255 and a boolean endofWord; I/ Set to true if prefix associated with this node is // also a word. // Constructor for new, empty node with NUMCHILDREN children // All the children are automatically initialized to null public WordTreelode(O children = new ilordTreeNode[NUCHILDREN); endofword- false depth = 0; charInParent = (char) 0; *Add a child to current node. The child is associated with the " character specified by the method parameter. Hake sure you set as * many fields in the child node as you can To implement this method, see the comment above the inner class * TreeNode declaration public WordTreeNode createChild(char c) WordTreeNode child-new WordTreeNode) /ADD YOUR CODE BELOW HERE ADD YOUR CODE ABOVE HERE return child;Explanation / Answer
Answer: createChild() method implementation:
public wordTreeNode createChild(char c){
WordTreeNode child=new WordTreeNode();
//sets children , depth, endOfWord parameters inside the constructor
child.charInParent=c;
//charInParent field is overriden or changed to value c which is passed as argument
return child;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.