title: converting from postfix to infix using stacks
body: <p>I'm currently working on a project converting from postfix to infix using stacks in the form of linked lists. I'm currently trying to read in the whole line as a string then placing it into a character array then when a symbol is found placing one element into a right operand another into a left operand then printing it back out inlcuding the operator. however after placing the first item into the left operand and then popping the stack im not able to place the other item into the right operand. What could be the problem? I its with my pop fucntion. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include "stack.h"
  
  stack::~stack()
  {
      cout&lt;&lt;"Inside !stack \n";
      while(s_top != 0)
      {
          pop();
      }
  }
  
  void stack::pop()
  {
      cout&lt;&lt;"Inside pop \n";
      stack_node *p;
  
      if (s_top != 0)
      {
          p = s_top;
          s_top = s_top-&gt;next;
          delete p;
      }
  
  }
  
  void stack::push(char a)
  {
      cout&lt;&lt;"Inside push \n";
      stack_node *p = new stack_node;
  
      p-&gt;data = a;
      p-&gt;next = s_top;
      s_top = p;
  }
  
  void stack::print()
  {
      cout&lt;&lt;"Inside print \n";
  
      for(stack_node *p = s_top; p!=0; p=p-&gt;next)
      {
          cout&lt;&lt;p-&gt;data&lt;&lt;endl;
      }
  }
  
  stack_element stack::top()
  {
      cout&lt;&lt;"Inside top \n";
  
      if (s_top == 0)
      {
          exit(1);
      }
      else
      {
          return s_top-&gt;data;
      }
  }
  
  /*stack::stack(const stack &amp; Org)
  {
      cout&lt;&lt;"Inside the Copy Constructor\n";
      stack_node *p=Org.s_top;
  
      (*this).s_top = 0;
  
      while(p!=0)
      {
          (*this).push(p-&gt;data);
          p=p-&gt;next;  
      }
  }
  </code></pre>
  
  <p>and here is my cpp where it doesnt completely work</p>
  
  <pre><code>#include "stack.h"
  
  string convert(string expression){
  
  stack c;
  
  string post = " ";
  string rightop="";
  string leftop="";
  string op =" ";
  
  for (int i =0; i&lt;expression.length();i++){
  c.push(expression[i]);
  
  if(expression[i]=='*'||'+'||'-'||'/'){
  cout&lt;&lt;c.top()&lt;&lt;endl;
  leftop=c.top();
  
  
  c.pop();
  
  
  rightop=c.top();
  cout&lt;&lt;rightop&lt;&lt;endl;
  c.pop();
  op=c.top();
  
  c.pop();
  }
  }
  
  }
  
  
  
  int main(){
  
  string expression;
  cout&lt;&lt;" Enter a Post Fix expression: ";
  
  getline(cin,expression);
  
  convert(expression);
  
  return 0;
  
  }
  </code></pre>