# Arithmetic Stacks

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 10-21-2008, 05:23 PM
Norm
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, 07:50 PM
unc123w
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, 09:24 PM
Norm
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?
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12