Explain the infix to post fix conversion algorithm.

Answers

This answer is not selected as best answer. This answer may not be sufficient for exam.

Your limit has been exceed. We have implemented this system because, We got difficulty on managing our servers. Please donate some amount to remove this limit.

Quota: 0 / 30

Donate

Algorithm to convert infix to postfix expression

  1. Scan the infix string from left to right.
  2. Initialize an empty stack.
  3. If the scanned character is an operand, add it to postfix sting
  4. If the scanned character is an operator, PUSH the character to stack.
  5. If the top operator in stack has equal or higher precedence than scanned operator then POP the operator present in stack and add it to postfix string else PUSH the scanned character to stack.
  6. If the scanned character is a left parenthesis ‘(‘, PUSH it to stack.
  7. If the scanned character is a right parenthesis ‘)’, POP and add to postfix string from stack until an ‘(‘ is encountered. Ignore both ‘(‘ and ‘)’.
  8. Repeat step 3-7 till all the characters are scanned.
  9. After all character are scanned POP the characters and add to postfix string from the stack until it is not empty.

Example:

Infix expression: A*B+C

characters stacks Postfix expression
A   A
* * A
B * AB
+ + AB*
C + AB*C
    AB*C+

Postfix expression: AB*C+

If you found any type of error on the answer then please mention on the comment or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .