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

?

[852 byte] By [dima7amdolilaha] at [2007-11-27 3:37:14]
# 1
Please continue in your original thread: http://forum.java.sun.com/thread.jspa?threadID=5169403
prometheuzza at 2007-7-12 8:40:31 > top of Java-index,Other Topics,Algorithms...