以下方法是 HuffmanTree 类的一部分。但它有点不同,因为它不是无效的。我写了以下方法,但它不打印侧面。你能帮帮我吗?谢谢!
public String printSideways() {
StringBuilder s = new StringBuilder("");
printSideways(overallRoot, s , 0);
return printSideways(); // I'm not sure about this part
}
private void printSideways(HuffmanNode root, StringBuilder s, int level) {
if (root != null) {
printSideways(root.right, s.append(root.toString()), level+1);
for(int i = 0; i < level; i++){
System.out.print(" ");
}
System.out.println(root.toString());
printSideways(root.left, s.append(root.toString()) , level+1);
}
}