Problem

Modify the expression evaluator case study program from this chapter to make a new program...

Modify the expression evaluator case study program from this chapter to make a new program that accepts as input a fully parenthesized infix expression and returns a string representing an equivalent postfix expression. Postfix expressions are ones where each operator follows its two operands, such as 1 2 + rather than 1 + 2. Postfix expressions are elegant in that they do not need parentheses. For example, the given infix expression:

(9 + (8 * 7 − (6 / 5 ^ 4) * 3) * 2))

is equivalent to the following postfix expression:

9 8 7 * 6 5 4 ^ / 3 * − 2 * +

Your algorithm should read the expression token by token, using a stack to store operators. (You don’t need the values stack from the original case study anymore.) Instead, each time a number is encountered, append it to a string that you are building up. Each time a right parenthesis is encountered, pop the stack to get an operator and append it to the string you are building up. Leave in place the rest of the code to preserve the error checking. Return the string "illegal expression" if an error is encountered.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT