Question: 2. The following algorithm is used to generate the postfix notation. If an input is a number (operand) is read, it is directly forwarded to

2. The following algorithm is used to generate the postfix notation.

  • If an input is a number (operand) is read, it is directly forwarded to the result string (the postfix).
  • If an input is an operator, it is first popped all operators from the top of the stack which have same or higher priority (the precedence levels in Ch. 7) to the result string (the postfix). Then push the current input operator onto the stack.
  • An opening bracket is just pushed onto the stack.
  • If a closing bracket is input, all elements on the stack are popped to the postfix string until we reach the opening bracket. The opening and closing brackets are deleted (not added to the postfix string).
  • If all token of the input are processed but the stack is not empty (which is the normal case), all remaining token are popped from the stack and appended to the postfix string.

For example, the postfix string of (3 + 5) * 2 + (6 - 3) is 3 5 + 2 * 6 3 - +

Use the same algorithm to write the postfix string for 3 + 5 * 2 + 6 3 *2

Write a program (Java and C++) to process the algorithm in Question 2 above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!