Infix to Postfix Conversion - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Infix to Postfix Conversion

Description:

Unstack & discard the '('. Discard the ')' if operator ... if (operator) apply to top 2 stack items and replace them (on the stack) with ... – PowerPoint PPT presentation

Number of Views:1736
Avg rating:3.0/5.0
Slides: 5
Provided by: dennisf5
Category:

less

Transcript and Presenter's Notes

Title: Infix to Postfix Conversion


1
Infix to Postfix Conversion
  • 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) lt precedence (top)
  • unstack and output operators
  • unstack and output any operators remaining on
    stack
  • Precedence (high to low) / - (

4
Evaluating Postfix
  • while (more input)
  • if (operand) push on stack
  • if (operator) apply to top 2 stack items and
    replace them (on the stack) with the result of
    the operation
  • Should have one item on the operand stack - value
    of the expression.
Write a Comment
User Comments (0)
About PowerShow.com