Page 659 - Computer science 868 Class 12
P. 659

72                  pfx +=  ob.pop();
                   73              return pfx;

                   74          }
                   75          int prec(char x)
                   76          {

                   77              if (x == '+' || x == '-')

                   78                  return 1;
                   79              else if (x == '*' || x == '/' || x == '%')
                   80                  return 2;

                   81              else
                   82                  return 0;

                   83          }
                   84

                   85          public static void main()
                   86          {

                   87              Convert ob=new Convert();
                   88              Scanner sc=new Scanner(System.in);

                   89              String expn;
                   90              //input infix expression

                   91              System.out.print("\nEnter the infix expression : ");
                   92              expn= sc.next();

                   93              //output as postfix
                   94              String p=ob.toPostfix(expn);

                   95              System.out.println("Postfix expression is: " +p );
                   96          }

                   97      }

                 The output of the preceding program is as follows:
                 Enter the infix expression : A+B*C

                 Postfix expression is: ABC*+
                 Enter the infix expression : (A+B+C-D/E)

                 Postfix expression is: AB+C+DE/-











                                                                                                                       657
                                                                                                       Sample Projects  657
   654   655   656   657   658   659   660   661   662   663   664