Presentation is loading. Please wait.

Presentation is loading. Please wait.

Infix to Postfix Conversion

Similar presentations


Presentation on theme: "Infix to Postfix Conversion"— Presentation transcript:

1 Infix to Postfix Conversion
CS212 & CS240 DJ Foreman

2 The algorithms convert infix notation to postfix
use a stack of operators evaluate a postfix expression uses stack of operands evaluate an infix expression use (1) and (2) together

3 Infix to Postfix (algorithm 1)
while (more input ) if '(' push on stack with priority 0 if operand - send to output if ')' output operators till '('. Unstack & discard the '('. Discard the ')' if operator while precedence (operator) < precedence (top) unstack and output operators unstack and output any operators remaining on stack Precedence (high to low): ^ * / + - (

4 Evaluating Postfix (algorithm 2)
while (more input) if (operand) push on stack if (operator) apply to top 2 (previous) stack items and replace them (on the stack) with the result of the operation When no input remains, remaining item on the operand stack is value of the expression


Download ppt "Infix to Postfix Conversion"

Similar presentations


Ads by Google