/** Start creating codes and putting them inside each node */ private void codings(HuffBaseNode rt) { if (rt instanceof HuffInternalNode) { if (((HuffInternalNode) rt).left() != null) { ((HuffInternalNode) rt).left().setCode(rt.getCode() + "0"); codings(((HuffInternalNode) rt).left()); } if (((HuffInternalNode) rt).right() != null) { ((HuffInternalNode) rt).right().setCode(rt.getCode() + "1"); codings(((HuffInternalNode) rt).right()); } } }
/** * Get string of codings of this HuffTree object * * @return codings of root */ public String getCode() { return root.getCode(); }