title: Convert prefix to postfix using stack
body: <p>I was told to write a program turning the prefix form to postfix form using stack.<br>
  The output I have now should be correct when I use paper and pencil to implement the function.  However, the result shown in the command window is strange.</p>
  
  <p>Actual output:</p>
  
  <pre><code>prefix  : A
  postfix : A
  
  prefix  : +*AB/CD
  postfix : AB*CD/+
  
  prefix  : +-*$ABCD//EF+GH
  postfix : AB$C*D-EF/GH+/H
  
  prefix  : +D/E+$*ABCF
  postfix : DEAB*C$F+/F
  
  prefix  : /-*A+BCD-E+FG
  postfix : ABC+DEFG+-+FG
  </code></pre>
  
  <p>Correct output:</p>
  
  <pre><code>prefix  : A
  postfix : A
  
  prefix  : +*AB/CD
  postfix : AB*CD/+
  
  prefix  : +-*$ABCD//EF+GH
  postfix : AB$C*D-EF/GH+/+
  
  prefix  : +D/E+$*ABCF
  postfix : DEAB*C$F+/+
  
  prefix  : /-*A+BCD-E+FG
  postfix : ABC+*D-EFG+-/
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>void prefix_to_postfix(string&amp; prefix, string&amp; postfix)
  {
  //Convert the input prefix expression to postfix format
  
  postfix = prefix;   //initialize the postfix string to the same length of the         prefix string
  
  stack&lt;stackItem&gt; S;
  stackItem x;
  int k = 0;  //index for accessing char of the postfix string
  
  for (int i = 0; i &lt; prefix.length(); i++)  //process each char in the prefix string from left to right
  {
      char c = prefix[i];
  
      if(prefix.length() == 1)
          break;
  
      //Implement the body of the for-loop        
      if(isOperator(c))
      {
          x.symb = c;
          x.count = 0;
          S.push(x);
      }
      else
      {
          S.top().count++;
          postfix[k++] = c;
  
          if(S.top().count == 2)
          {
              postfix[k++] = S.top().symb;
              S.pop();
              S.top().count++;
          }
      }
      if(i == (prefix.length() - 1))
      {
          postfix[k++] = S.top().symb;
          S.pop();
      }
  
  }
  }
  </code></pre>