Here is my function, i seed it with the root node of my tree and a character to be found inside the tree. It successfully returns me the alphabet to be searched but it does not give me the path to the element. Im a bit stuck any help would be appriciated
public Node traversingTree(Node root,String charToFind){
Node tempRoot = root;
if (root != null){
if (charToFind.equals(root.getAlphabet()))
{
//Another Point of consideration
System.out.print(root.getAlphabet());
System.out.println(": "+pathCodes);
pathCodes.clear();
return root;
}
Node result;
if ((result = traversingTree(root.leftChild, charToFind)) != null){
pathCodes.add("0");
return result;
}else
pathCodes.add("1");
return traversingTree(root.rightChild, charToFind);
}
}
pathCodes.clear();
return null;
}