1 / 11

Infix to Postfix Conversion: Queue Applications

Learn how to convert infix expressions to postfix notation using queues in this informative lecture. Understand the disadvantages of infix notation and the step-by-step process of evaluating infix expressions. Follow examples and grasp the concept easily.

arruda
Download Presentation

Infix to Postfix Conversion: Queue Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Queue Applications Lecture 31 Mon, Apr 9, 2007

  2. Infix Expression Evaluation • An infix expression with one (binary) operator is written in the order: left-operand, operator, right-operand. • Example: 3 + 4 Queues

  3. Disadvantages of Infix Notation • Parentheses are often needed to indicate order of operation. • Example: (3 + 4) * (5 + 6) • Operators follow a precedence hierarchy. • Example: 3 + 4 * 5 – 6 / 7 • Operators have left or right associativity. • Example: 100 – 50 – 10 – 5 – 1 Queues

  4. Infix Expression Evaluation • To evaluate an infix expression, we first convert it to postfix. • Then begin with an empty stack and an empty queue. • Process the tokens from left to right according to the following rules. • If the token is a number, • Enqueue the token. • If the token is a left parenthesis, • Push the token onto the stack. Queues

  5. Infix Expression Evaluation • If the token is a right parenthesis, • Pop tokens off the stack and enqueue them until a left parenthesis is popped. • Discard the right and left parentheses. Queues

  6. Infix Expression Evaluation • If the token is an operator, • Pop tokens off the stack and enqueue them until • An operator of lower precedence is on top of the stack, or • A left parenthesis is on top of the stack, or • The stack is empty. • Push the operator onto the stack. Queues

  7. Infix Expression Evaluation • After processing the last token • Pop all tokens off the stack and enqueue them. • The queue now contains the expression in post-fix notation. • Process the queue as a post-fix expression. Queues

  8. Example • Convert the expression ((1 + 2)*3 – 4/(5 + 6 – 7*8))*9 7 from infix to postfix notation. Queues

  9. Example Queues

  10. Example Queues

  11. Example Queues

More Related