Monday, March 4, 2019

EVALUATING POSTFIX EXPRESSION

Evaluating the postfix conversion has following steps,

  1. If the character is an operand push its associated values onto the stack.
  2. If the character is an operator,pop two values from the stack apply the operator to them and push the result on the stack.

EXAMPLE


Evaluate the postfix Expression 6523+8*+3+*

  • First four symbols are placed on the stack.


  • Next '+' is read ,so pop 3&2 from stack and their sum 5 is pushed.
                           

  • Next 8 pushed
                             

  • Now '*', so 5*8=40 is pushed   
 
  • Now  '+' ,so 5+40=45 is pushed on the stack.                    


                                                  

  • Now 3 pushed,

                                              

  • Next '+' ,so 3+45=48 is pushed,

                                                

  • Finally '*' ,6*48=288 is pushed,
                                        




No comments:

Post a Comment