/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.trying.stackandqueue;

/**
 * @author cwenao
 * @version $Id Infix2PostfixByStack.java, v 0.1 2017-09-27 16:06 cwenao Exp $$
 */
public class Infix2PostfixByStack {
    static int prec(char operation) {
        switch (operation) {
            case '+':
            case '-':
                return 1;
            case '*':
            case '/':
                return 2;
            case '^':
                return 3;
            default:
                return -1;
        }
    }


}

@@ -102,16 +102,41 @@
 queue;%0A%0A
+import java.util.Stack;%0A%0A
 /**%0A * @
@@ -589,11 +589,1216 @@
 %0A    %7D%0A%0A
+    public static String infix2Postfix(String exp) %7B%0A        StringBuffer sb = new StringBuffer();%0A        Stack%3CCharacter%3E stack = new Stack%3C%3E();%0A%0A        for (int i = 0; i %3C exp.length(); i++) %7B%0A            char ch = exp.charAt(i);%0A            if (Character.isLetterOrDigit(ch)) %7B%0A                sb.append(ch);%0A            %7D else if ('(' == ch) %7B%0A                stack.push(ch);%0A            %7D else if (')' == ch) %7B%0A                while (!stack.isEmpty() && '(' != stack.peek()) %7B%0A                    sb.append(stack.pop());%0A                %7D%0A                if (!stack.isEmpty() && '(' != stack.peek()) %7B%0A                    return %22Invalid exp%22;%0A                %7D else %7B%0A                    stack.pop();%0A                %7D%0A            %7D else %7B%0A                while (!stack.isEmpty() && prec(ch) %3C= prec(stack.peek())) %7B%0A                    sb.append(stack.pop());%0A                %7D%0A                stack.push(ch);%0A            %7D%0A        %7D%0A        while (!stack.isEmpty()) %7B%0A            sb.append(stack.pop());%0A        %7D%0A        return sb.toString();%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        String exp = %22a+b*(c%5Ed-e)%5E(f+g*h)-i%22;%0A        System.out.println(infix2Postfix(exp));%0A    %7D
 %0A%7D%0A

update the Infix2Postfix