recursion - Traversing Huffman Tree in Java -
i'm trying utilize recursive method traverse huffman tree, , each leaf node, add together code record arraylist. have far.
private void traverse(arraylist<code> code, binarytreenode<letter> node, string prefix) { // todo: fill in method if (root!=null){ traverse(code, node.left, prefix); } if (root!=null){ traverse(code, node.right, prefix); } if(node.left==null && node.right==null){ code.add(node); }
the code.add(node) giving error well.
arraylist code
type code
, @ lastly line adding node type object
code
.what need alter code match following:
one more thing include value of node ( assuming want add together value of each node)
private void traverse(arraylist<letter> code, binarytreenode<letter> node, string prefix) { // todo: fill in method if(node==null) return; //return if node empty. if (node!=null){ traverse(code, node.left, prefix); } if (node!=null){ traverse(code, node.right, prefix); } //if want include node value ur array add together code.add(node.getdata()); //assuming binarytreenode has method getdata()
}
note: coulnd't figure out string prefix
supposed be. left is.
java recursion tree huffman-coding
No comments:
Post a Comment