0

I am trying to convert a postfix expression to an expression tree. My method is to have a stack of JTree for the expression tree, a stack of string for paranthesis and a stack of nodes for operators.

Eg postfi ( C ( A B OR ) AND )

I am able to populate the stacks but when I encounter a ')' I want to create a new JTree in the JTree stack which will contain the operator stack's pop (operator JTree) as root, and the two expression JTrees (pop the expression stack twice) as children.

When I try to create a new tree, as above, I am unable to add the two popped JTrees to the parent operator JTree. Is there another way to do this? How can I nest 2 JTrees? Please tell me if I am not clear/ need to post code.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
P R
  • 1,293
  • 7
  • 28
  • 58
  • I've not seen parentheses in postfix notation. See also this [Q&A](http://stackoverflow.com/q/423898/230513). – trashgod Apr 23 '13 at 21:33
  • Yes, I'm trying to implement that. – P R Apr 23 '13 at 21:54
  • In fact, I found another way to do it. Instead of making them all JTrees, I'm making the type nodes and I have solved the issue. Thanks :) – P R Apr 23 '13 at 21:55
  • You can [answer your own question](http://meta.stackexchange.com/q/17463/163188). – trashgod Apr 23 '13 at 21:58

0 Answers0