【发布时间】:2019-01-20 18:25:21
【问题描述】:
public void printTree(node root)
{
if(root != null)
{
printTree(root.left);
System.out.print(root.word + " " + root.line+" ");
String tempStr=root.word; int tempLn=root.line; //don't know how to use it
printTree(root.right);
}
}
假设树已经按字典顺序排序。
比如文件是这样的:
aaa
zzz
the the the the
输出应该是这样的:
aaa line: 1
the line: 3 3 3 3
zzz line: 2
我的代码现在多次显示相同的单词。我不知道如何组织这段代码。
【问题讨论】:
-
您介意发布您的整个树源代码吗?
-
@Leo:我编辑了我的帖子..
-
我们可以修改你的树的方法吗?您必须在树中行走时呈现此结果,还是可以在其他结构中累积数据?您只能使用您引用的临时工,或者我们可以使用节点临时工吗?
标签: java printing binary-tree