I'm trying to use pre-order traversal to find a node in a binary tree made up of the characters a-z and A-Z, where going left is marked as "0" and going right is marked as "1", so that a correct output would look like "00" for a node that is two branches to the left. The nodes are not sorted.
So far I have this:
static String routeNum = "";
private static String onePath(BinaryNodeInterface<Character> root, String route) {
BinaryNodeInterface<Character> temp = root;
if(temp != null){
if(temp.hasLeftChild()){
routeNum = onePath(temp.getLeftChild(),route+"0");
}
if(temp.hasRightChild()){
routeNum = onePath(temp.getRightChild(), route+"1");
}
}
System.out.print(route);
return route;
}
The output indicates that I am getting to the right nodes but it doesn't print the path.
You are never calling a print method. You can use:
to print out the route String.