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));
}
}
打印路径时,它只打印最后一条路径,或者只打印我的树中的一条路径。有人知道为什么吗??
谢谢你!