 <ul> <li>Using <code>stack.top()</code> is illegal if the <code>stack</code> is empty.<br> Change <code>while((!highPrecedence(stack.top(),c)) &amp;&amp; (stack.size()!=0)){</code><br> to <code>while((!stack.empty()) &amp;&amp; (!highPrecedence(stack.top(),c))){</code></li> <li>The initiali value of <code>i</code> is not good and you are printing uninitialized variable, which has indeterminate value.<br> Change <code>int i=0;</code> to <code>int i=-1;</code></li> </ul>