0% found this document useful (0 votes)
47 views18 pages

In Fix To Post Fix Conversion

Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views18 pages

In Fix To Post Fix Conversion

Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Infix to postfix conversion

Read the tokens from a vector infixVect of tokens (strings) of an infix expression  When the token is an operand Add it to the end of the vector postfixVect of token (strings) that is used to store the corresponding postfix expression  When the token is a left or right parenthesis or an operator If the token x is (


Push_back the token x to the end of the vector stackVect of token (strings) that simulates a stack Repeatedly pop_back a token y from stackVect and push_back that token y to postfixVect until ( is encountered in the end of stackVect. Then pop_back ( from stackVect. If stackVect is already empty before finding a (, that expression is not a valid expression. Step 1: Check the token y currently in the end of stackVect. Step 2: If (case 1) stackVect is not empty and (case 2) y is not ( and (case 3) y is an operator of higer or equal precedence than that of x, then pop_back the token y from stackVect and push_back the token y to postfixVect, and go to Step 1 again. Step 3: If (case 1) stackVect is already empty or (case 2) y is ( or (case 3) y is an operator of lower precedence than that of x, then push_back the token x into stackVect.

if the token x is )


if the token x is a regular operator


 

When all tokens in infixVect are processed as described above, repeatedly pop_back a token y from stackVect and push_back that token y to postfixVect until stackVect is empty

Infix to postfix conversion


infixVect (a+b-c)*d(e+f) postfixVect

Infix to postfix conversion


stackVect infixVect a+b-c)*d(e+f) postfixVect

Infix to postfix conversion


stackVect infixVect +b-c)*d(e+f) postfixVect a

Infix to postfix conversion


stackVect infixVect b-c)*d(e+f) postfixVect a + (

Infix to postfix conversion


stackVect infixVect -c)*d(e+f) postfixVect ab + (

Infix to postfix conversion


stackVect infixVect c)*d(e+f) postfixVect ab+ (

Infix to postfix conversion


stackVect infixVect )*d(e+f) postfixVect ab+c (

Infix to postfix conversion


stackVect infixVect *d(e+f) postfixVect ab+c-

Infix to postfix conversion


stackVect infixVect d(e+f) postfixVect ab+c-

Infix to postfix conversion


stackVect infixVect (e+f) postfixVect ab+c-d

Infix to postfix conversion


stackVect infixVect (e+f) postfixVect ab+cd*

Infix to postfix conversion


stackVect infixVect e+f) postfixVect ab+cd* ( -

Infix to postfix conversion


stackVect infixVect +f) postfixVect ab+cd*e ( -

Infix to postfix conversion


stackVect infixVect f) postfixVect + ( ab+cd*e

Infix to postfix conversion


stackVect infixVect ) postfixVect + ( ab+cd*ef

Infix to postfix conversion


stackVect infixVect

postfixVect ab+cd*ef+

Infix to postfix conversion


stackVect infixVect

postfixVect ab+cd*ef+-

You might also like