Header Ads Widget

Algorithm to convert infix expression into postfix expression.

 Algorithm:-
                       Suppose Q is an arithmetic expression written in infix notation . this algorithm find equivalent postfix expression P. 
  1. Push “(“onto Stack, and add “)” to the end of Q.
  2. Scan Q from left to right and repeat Step 3 to 6 for each element of Q until the Stack is empty.
  3. If an operand is encountered, add it to P.
  4. If a left parenthesis is encountered, push it onto Stack.
  5. If an operator is encountered ,then:
    1. Repeatedly pop from Stack and add to P each operator (on the top of Stack) which has the same precedence as or higher precedence than operator.
    2. Add operator to Stack.
      [End of If]
  6. If a right parenthesis is encountered ,then:
    1. Repeatedly pop from Stack and add to P each operator (on the top of Stack) until a left parenthesis is encountered.
    2. Remove the left Parenthesis

Post a Comment

0 Comments