Need Help
I am trying to rebuild a tree from its preorder traversal
(A (B (C) ()) (E )) where each (X) is a node
I have this (A (B (C) ()) (E )) as a string.
here is what I did .
Build generic BinTree with Data as charcter and left and right tree
and each tree is built recursively .It seem to me logically done
public BinTree(char inData,BinTree A,BinTree B)
{ root = new BTNode(inData,A.root,B.root); }
}
int i=0;
int j=i+2;
public BinTree buildTree(String in){
if ((in.charAt(i)=='(')&& (in.charAt(j)==')'))
{
BinTree A = new BinTree(in.charAt(i+1),buildTree(in.substring(j)),buildTree(in.substring(j+3)));
return A;
else
buildTree(in.substring(i+2));
}
}
But I dont think this is going to work for the else part
?

