Parsing String to TreeNode
- by Krusu70
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:
level A (String: name), B - Child (TreeNode), C - Sibling (TreeNode)
level B (String: name), D - Child of B (TreeNode), E - Sibling of B (TreeNode)
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).