【发布时间】:2013-04-02 06:19:12
【问题描述】:
static void printAllPathsFromRootToLeaf (BinaryTree<Integer> tree, ArrayList<Integer> path)
{
if (tree.isEmpty())
{
System.out.println("Tree is Empty");
return;
}
path.add(tree.root());
if (tree.left().isEmpty() && tree.right().isEmpty())
{
System.out.println(path);
printSum(path);
//return;
}
else
{
printAllPathsFromRootToLeaf(tree.left(),new ArrayList(path));
printAllPathsFromRootToLeaf(tree.right(),new ArrayList(path));
}
}
当打印路径时,它只打印最后一条路径,或者只打印我树中的一条路径。有人知道为什么吗??
谢谢!
【问题讨论】:
标签: java tree binary-tree binary-search-tree binary-search