TOPIC : INFIX , POSTFIX , PREFIX EXPRESSIONS
PRESENTED BY :
CONTENTS.
 What are INFIX , POSTFIX , PREFIX EXPRESIONS
 Some rules for conversion
 Some Examples
 INFIX : an infix expression is one in which operators are located between their
operands.
Eg. (A + (B * C)) + D)
 POSTFIX : an postfix expression is one in which operators are located after its
operands, according to their precedence.
Eg. A B C * + D +
 PREFIX : an prefix expression is one in which operators are located before its operands,
according to their precedence.
Eg. + + A * B C D
What is INFIX , POSTFIX , PREFIX ?
SOME RULES FOR CONVERSION
 Highest priority -> ^
 Next priority -> / , *
 Least priority -> + , -
 No two operators of same priority can stay together in stack .
 Least priority operator cannot be placed above the highest priority operator
in stack.
INFIX TO POSTFIX
 Eg. (A + B / C * (D + E ) )
Input String Output Operator Stack
(A + B / C * (D + E ) ) (
(A + B / C * (D + E ) ) A (
(A + B / C * (D + E ) ) A (+
(A + B / C * (D + E ) ) A B (+
(A + B / C * (D + E ) ) A B (+/
(A + B / C * (D + E ) ) A B C (+/
(A + B / C * (D + E ) ) A B C / (+*
(A + B / C * (D + E ) ) A B C /
(+*(
(A + B / C * (D + E ) ) A B C / D (+*(+
(A + B / C * (D + E ) ) A B C / D E (+*(+
(A + B / C * (D + E ) ) A B C / D E + (+*
(A + B / C * (D + E ) ) A B C / D E + *+
INFIX TO PREFIX
 Eg . A + B * C – D + E
Input String Operator Stack Output
E E
+ + E
D + ED
- - ED+
C - ED+C
* - * ED+C
( - * ( ED+C
B+ - * ( ED+CB
A - * ( + ED+CBA
) - * ED+CBA+
- ED+CBA+*
ED+CBA+*-
OUTPUT -*+ABC+DE
C code for infix to postfix
 Lets see some examples

DS1.pptx

  • 1.
    TOPIC : INFIX, POSTFIX , PREFIX EXPRESSIONS PRESENTED BY :
  • 2.
    CONTENTS.  What areINFIX , POSTFIX , PREFIX EXPRESIONS  Some rules for conversion  Some Examples
  • 3.
     INFIX :an infix expression is one in which operators are located between their operands. Eg. (A + (B * C)) + D)  POSTFIX : an postfix expression is one in which operators are located after its operands, according to their precedence. Eg. A B C * + D +  PREFIX : an prefix expression is one in which operators are located before its operands, according to their precedence. Eg. + + A * B C D What is INFIX , POSTFIX , PREFIX ?
  • 4.
    SOME RULES FORCONVERSION  Highest priority -> ^  Next priority -> / , *  Least priority -> + , -  No two operators of same priority can stay together in stack .  Least priority operator cannot be placed above the highest priority operator in stack.
  • 5.
    INFIX TO POSTFIX Eg. (A + B / C * (D + E ) ) Input String Output Operator Stack (A + B / C * (D + E ) ) ( (A + B / C * (D + E ) ) A ( (A + B / C * (D + E ) ) A (+ (A + B / C * (D + E ) ) A B (+ (A + B / C * (D + E ) ) A B (+/ (A + B / C * (D + E ) ) A B C (+/ (A + B / C * (D + E ) ) A B C / (+* (A + B / C * (D + E ) ) A B C / (+*( (A + B / C * (D + E ) ) A B C / D (+*(+ (A + B / C * (D + E ) ) A B C / D E (+*(+ (A + B / C * (D + E ) ) A B C / D E + (+* (A + B / C * (D + E ) ) A B C / D E + *+
  • 6.
    INFIX TO PREFIX Eg . A + B * C – D + E Input String Operator Stack Output E E + + E D + ED - - ED+ C - ED+C * - * ED+C ( - * ( ED+C B+ - * ( ED+CB A - * ( + ED+CBA ) - * ED+CBA+ - ED+CBA+* ED+CBA+*- OUTPUT -*+ABC+DE
  • 7.
    C code forinfix to postfix  Lets see some examples