title: Precedence of operators in infix to postfix conversion
body: <p>I'm creating a program in C that converts  an expression in infix form to postfix form using the reverse polish algorithm through a stack implementation. However, I'm having trouble with how an incoming token having the same precedence as the topmost element of the stack should be placed. For example, given the infix form: (a+b-c/d+e^f^2), the postfix form should be: ab+cd/-ef2^^+. However, my program outputs: ab+cd/-ef^2^+. I think the problem lies with this part of my code:</p>
  
  <pre><code>while(priority(token) &lt;= priority(top_elem(&amp;S)) &amp;&amp; !isStackEmpty(&amp;S)){
      x = POP(&amp;S);
      printf("%c", x);
  }
  PUSH(&amp;S, token);
  </code></pre>
  
  <p>By the way, this part only executes for operator tokens ('+', '-', '<em>', '/', '^) and the open parenthesis. The priority function returns 0 for the open parenthesis, 1 for  '+' and '-', 2 for '</em>' and '/', and 3 for '^'.</p>
  
  <p>I was wondering what I should change in my program. It executes fine for other inputs, though.</p>