Parsing String to TreeNode

Posted by Krusu70 on Stack Overflow See other posts from Stack Overflow or by Krusu70
Published on 2012-11-06T16:53:37Z Indexed on 2012/11/06 17:00 UTC
Read the original article Hit count: 160

Filed under:
|
|
|

Anyone have a good algorithm how to parse a String to TreeNode in Java?

Let's say we have a string s which says how to build a TreeNode. A(B,C) means that A is the name (String) of TreeNode, B is child of A (Treenode), C is sibling of A (TreeNode).

So if I call function with string A(B(D,E(F,G)),C) (just a example), then I get a TreeNode equals to:

  1. level A (String: name), B - Child (TreeNode), C - Sibling (TreeNode)
  2. level B (String: name), D - Child of B (TreeNode), E - Sibling of B (TreeNode)
  3. level E (String: name), F - Child of E (TreeNode), G - Sibling of E (TreeNode)

The name may not be 1 letter, it could be like real name (many letters).

© Stack Overflow or respective owner

Related posts about java

Related posts about string