title: Converting infix to postfix using stack data structure with linked list
body: <p>I am trying to create a program to convert an infix expression to  a postfix expression using stack data structure in c++ using a structure Node. The related functions are there to push, pop values from the stack. The program compiles but after i enter a infix expression example 'a+b' in the output window, there is a runtime error.
  Here is the complete code..</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include&lt;cstring&gt;
  
  using namespace std;
  
  struct Node{
      char data;
      struct Node * next;
  }*top=NULL;
  
  void Push(char x)
  {   struct Node* p=new Node;
      if(p==NULL)
          cout&lt;&lt;"\nStack Overflow";
      else{
          p-&gt;data=x;
          p-&gt;next=top;
          top=p;
      }
  }  
  
  char Pop(){
      int x=-1;
      struct Node * p;
      if(top==NULL)
          cout&lt;&lt;"\nStack is Empty";
      else{
           p=top;
           x=p-&gt;data;
           top = top-&gt;next;
           delete p;
      }
      return x;
  }
  
  int isEmpty(){
      return top?0:1;
  }
  
  int Pre(char ch){
      if(top==NULL)
          return 0;
      else if(ch == '-' || ch == '+')
          return 1;
      else if(ch == '*' || ch == '/')
          return 2;
      else
          return 3;
  }
  char * InToPost(char *infix){
      char *postfix = new char[strlen(infix)+1];
      int i=0,j=0;
      while(infix[i]!='\0')
      {
          if(Pre(infix[i]&gt;Pre(top-&gt;data)))
              Push(infix[i++]);
          else{
              while(Pre(infix[i])&lt;=Pre(top-&gt;data))
                  postfix[j++]= Pop();
            }
      }
      while(!isEmpty())
          postfix[j++]=Pop();
      postfix[j] = '\0';
      return postfix;
  }
  
  int main(){
      char *infix = new char[30];
      cin&gt;&gt;infix;
     cout&lt;&lt;InToPost(infix);
  }
  </code></pre>