views:

18

answers:

0

Let's say I have an expression tree encoded as a linear (array) representaion. The tree is constructed from the array by "filling" the tree in level-order, left-to-right and top-to-bottom. For example, the linear representation: +*243 would parse into the following tree:

         +
        / \
       /   \
      *     2
     / \
    /   \
   4     3

I know how to parse this tree into postfix notation. But what I'd like is to take the original linear representation and parse it into postfix notation without building the tree. I've done something similar in the past but can't remember how. I think I used an intermediate stack, somehow popping off the top operator, adding it to the postfix string and pushing it's arguments - the first characters in the original string yet to be parsed - onto the stack. Then repeat until the entire string has been parsed. Am I on the right track or is this simpler than I'm trying to make it?