I thought I asked this before:

Do you have the algorithm for doing that?

And you gave me an algorithm for evaluating an expression.

Do you have the alogrithm for converting an expression to a postfix string?

Printable View

- 10-21-2008, 04:23 PMNorm
I thought I asked this before:

Do you have the algorithm for doing that?

And you gave me an algorithm for evaluating an expression.

Do you have the alogrithm for converting an expression to a postfix string? - 10-21-2008, 06:50 PMunc123w
If the character is an operator, it's precedence gets compared to that of the operator on top of the operator stack. If the current operator has the same or lower precedence, the operator on top of the stack must be evalutated next. Pop that operator off the operator stack along with a pair of operands from the operand stack and writing a new line in the output table. The character selected to hold the result should then be pushed onto the operand stack. Next, the current operator should be compared to the new top of the operator stack. Continue to generate output lines until the top of the operator stack has lower precedence than the current operator or until it is empty. At this point, push the current operator onto the top of the stack and examine the next character in the data string. When the end of the string is reached, pop any remaining operator along with its operand pair just described. Push the result character onto the operand stack after each table line is generated.

- 10-21-2008, 08:24 PMNorm
At end of expression(end of the string), how is the output postfix string generated? Your description says " pop any remaining operator along with its operand pair just described."

Now can you write the code for that algorithm?