i am trying to print all root to leaf paths in a binary tree using java.
public void printAllRootToLeafPaths(Node node,ArrayList path)
{
if(node==null)
public void PrintAllPossiblePath(Node node,List nodelist)
{
if(node != null)
{
nodelist.add(node);
if(node.left != null)
{
PrintAllPossiblePath(node.left,nodelist);
}
if(node.right != null)
{
PrintAllPossiblePath(node.right,nodelist);
}
else if(node.left == null && node.right == null)
{
for(int i=0;i
nodelist.remove(node) is the key, it removes the element once it prints the respective path