title: Infix to Postfix using stacks and Precedence of Operators
body: <p>I know there are similar questions to this already on SO but I can't find one which solves the problem I'm having. I am trying to make a method which converts infix notation expressions to postfix notation, while implementing precedence of operators in order to get correct output.
  I have made my own stack class with the usual methods (push, pop, peek etc.) and it works absolutely fine. My problem is that for more complicated expressions such as A-(B+C^D^C)/D*B , I am getting the wrong output. The result of the conversion should be ABCDC^^+D/B*- whereas i keep on getting ABCDC^^+D/-B</p>
  
  <p>here is my method:</p>
  
  <pre><code>    public static String infixToPostfix(char[] expressionArray, CharStack opStack){
      String output = "";
      int length = expressionArray.length;
      for(int i = 0; i &lt; length; i++){    
          if(isOperatorOrBracket(expressionArray[i])){ 
              if(priorityAtInput(expressionArray[i]) &gt;= priorityAtStack(opStack.peek())){
                  opStack.push(expressionArray[i]);
              }else if(priorityAtInput(expressionArray[i]) == priorityAtStack(opStack.peek())){
                  output = output + expressionArray[i];
              }else{
                  while(opStack.peek() != '('){
                      output = output + opStack.pop();
                  }
                  opStack.pop();
              }
          }else{
              output = output + expressionArray[i];
          }
      }
      while(!opStack.empty()){
          if(opStack.peek() != '('){
              output = output + opStack.pop();
          }else if(opStack.peek() == '('){
              opStack.pop();
          }
      }
      return output;
  }
  </code></pre>
  
  <p>Please let me know if you need to any of the component methods. Any help greatly appreciated!</p>