title: Postfix to Infix conversion in C
body: <p>Can anyone help me with Postfix to Infix conversion in C, I tried several time but still not able to figure out the logic.</p>
  <p>I know the algo, its something like:<br></p>
  <ul>
  <li>Take the expression as input</li>
  <li>if the char is an operand, then push it into the stack</li>
  <li>if the char is an operator, then continuously pop two elements from the stack, place the operator between them, and then push the resultant expression into the stack</li>
  <li>Do the above steps until the whole expression is not read</li>
  </ul>
  <pre><code>#include&lt;stdio.h&gt;
  
  char st[100];
  int top = -1;
  
  void push(char el)
  {
    st[++top] = el; 
  }
  
  char pop()
  {
    return st[top--];
  }
  
  int isop(char val)
  {
    if (val == '+' || val == '-' || val == '*' || val == '/' || val == '%')
    {
      return 1;
    } else {
      return 0;
    }
  }
  void main()
  {
    char exp[50], v1, v2, ex;
    int i = 0;
  
    printf(&quot;Enter the expression: &quot;);
    gets(exp);
  
    while(exp[i] != '\0')
    {
      if(isop(exp[i]))
      {
        v1 = pop();
        v2 = pop();
        ex = exp[i];
  
      } else {
        push(exp[i]);
      }
      i++;
    }
  }
  </code></pre>
  <p>The only place where I am stuck at is, how will I push the resultant expression(expression obtained by placing the operator in between the two popped operands) again into the stack.</p>
  <p>Thanks.</p>