Operand is the quantity (unit of data) on which a mathematical Saturday, April 18, Data Structure. 9. Infix. Postfix. Prefix. A+B. AB+. +AB. Content about infix prefix and post fix and their conversion using the certain algorithms in computer world. Table 4: Additional Examples of Infix, Prefix, and Postfix . In this case, a stack is again the data structure of choice. However, as you scan the postfix expression.

Author: | Ganos JoJomi |

Country: | Dominican Republic |

Language: | English (Spanish) |

Genre: | Health and Food |

Published (Last): | 25 July 2011 |

Pages: | 136 |

PDF File Size: | 1.99 Mb |

ePub File Size: | 13.46 Mb |

ISBN: | 772-3-84742-396-8 |

Downloads: | 16124 |

Price: | Free* [*Free Regsitration Required] |

Uploader: | Vudokinos |

To evaluate expressions manually infix notation is helpful as it is easily understandable by the human brain. But infix expressions are hard to parse in a computer program hence it will be difficult to evaluate expressions using infix notation.

To reduce unfix complexity of expression evaluation Prefix or Postfix expressions are used in the computer programs.

In Postfix expressions, operators come after the operands. Below are an infix and respective Postfix expressions.

As mentioned in the above example, the Pstfix expression has the operator after the operands. To begin conversion of Infix to Postfix expression, first, we should know about operator precedence. Precedence of the operators takes a crucial place while evaluating expressions.

The top operator in the table has the highest precedence. As per the precedence, the operators will be pushed to the stack. If we encounter an operand we will write in the ptefix string, if we encounter an operator we will push it to an operator stack.

So now the two elements look like below.

## Conversion of Infix expression to Postfix expression using Stack data structure

Thus we processed all the tokens in the given expression, now we need to pop out the remaining tokens from the stack and have to add it to the expression string. Below is the given infix expression. The given expression has parentheses to denote the precedence. The first token to encounter is an open parenthesis, add it to the operator stack.

The second token to encounter is again an open parenthesis, add it to the stack. Then we have an operand, so add it to the expression string. Next token in the given infix expression is a close parenthesis, as we encountered a close parenthesis we should pop the expressions from the stack and add it to the expression string until an open parenthesis popped from the stack.

Next is an open parenthesis, so add it to the stack. Then a close parenthesis, as we saw earlier, we should not push it to the stack instead we should pop all the ln from the stack and add it to the expression string until we encounter an open parenthesis.

### Conversion of Infix expression to Postfix expression using Stack data structure

Next token is again a close paranthesis, so we will pop all the operators and add them to the expression string until we reach the open parenthesis and we will pop structured open parenthesis as well from the operator stack.

Add it to the expression string.

As we processed the whole infix expression, now the operator stack has to be cleared by popping out each remaining operator and adding them to the expression string. So the resultant Postfix expression infux look like below. Hope you would understand, if not please let me know by comment.

Sign in Get started. Conversion of Infix expression to Postfix expression using Stack data structure. So now the two elements look like below, Expression string: A B Operator Stack: So the resultant Postfix expression would look like below, Final Postfix expression: Never miss a story from codeburstwhen you sign up for Medium.

Get updates Get updates.