title: infix to postfix program
body: <p>I have written the following infix to postfix program but it's not working.
  My program takes input but doesn't show any result. Can anyone help find the problem in my program.
  And also it would be a great help if you tell if my Algorithm for converting infix to postfix is correct or not.</p>
  
  <pre><code>using namespace std;
  
  class Stack
  {
  private:
      int top;
      char s[mx];
  public:
      Stack()
      {
          top=-1;
      }
  
      void push(char c)
      {
          if(!stackFull())
          s[++top]=c;
      }
  
      void pop()
      {
          if(!stackEmpty())
          top--;
          else cout&lt;&lt;"Stack is empty"&lt;&lt;endl;
      }
  
      char topShow()
      {
          if(!stackEmpty())
          return s[top];
      }
  
      bool stackEmpty()
      {
          if(top==-1)
              return 1;
          else return 0;
      }
  
      bool stackFull()
      {
          if(top == (mx-1))
              return 1;
          else return 0;
      }
  };
  
  class Expression
  {
  private:
      char entry2;
      int precedence;
      char infix[mx];
      char postfix[mx];
  public:
  
  int prec(char symbol)
  {
      switch(symbol)
      {
          case '(':return 0; break;
          case '-':return 1; break;
          case '+':return 2; break;
          case '*':return 3; break;
          case '/':return 4; break;
      }
  }
  
  void Read()
  {
      cout&lt;&lt;"Enter the infix expression: ";cin&gt;&gt;infix;
      for(int i=0;infix[i]!='\0';i++)
      {
          convertToPostfix(infix[i]);
      }
  }
  
  void ShowResult()
  {
      cout&lt;&lt;"Postfix expression"&lt;&lt;endl;
      for(int j=0;postfix[j]!='\0';j++)
      {
          cout&lt;&lt;postfix[j];
      }
  }
  
  void convertToPostfix(char c)
  {
      int p=0;
      Stack myStack;
      precedence=prec(c);
      entry2=myStack.topShow();
      if(isdigit(c))
      {
          postfix[++p]=c;
      }
  
      if(precedence&gt;prec(entry2))
      {
          myStack.push(c);
      }
  
      if(precedence&lt;prec(entry2))
      {
          switch(c)
          {
              case '(': myStack.push(c); break;
              case ')': while(myStack.topShow()!= '(')
                          {
                              postfix[++p]=myStack.topShow();
                              myStack.pop();
                          };myStack.pop();break;
              case '+':
              case '-':
              case '*':
              case '/': while(prec(myStack.topShow())&gt;=precedence)
                          {
                              postfix[++p]=myStack.topShow();
                              myStack.pop();
                          };break;
          }
      }
  
  }
  
  };
  
  int main()
  {
      Expression myExp;
      myExp.Read();
      myExp.ShowResult();
      return 0;
  }
  </code></pre>