<p><ahref="https://www.includehelp.com/c/infix-to-postfix-conversion-using-stack-with-c-program.aspx"target="_blank">Infix to Postfix converter</a> implementation
Include dependency graph for infix_to_postfix2.c:</div>
<divclass="dyncontent">
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d1/de4/infix__to__postfix2_8c__incl.svg"width="524"height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<trclass="memdesc:"><tdclass="mdescLeft"> </td><tdclass="mdescRight">for printf() and scanf() <ahref="../../dd/d10/struct_stack.html#details">More...</a><br/></td></tr>
<trclass="memdesc:a90e051f23f741be4f8ca86c270d66489"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Function to push on the stack. <ahref="../../da/d96/infix__to__postfix2_8c.html#a90e051f23f741be4f8ca86c270d66489">More...</a><br/></td></tr>
<trclass="memdesc:a312e7f6c761a199c1369fbe651e084f0"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Function to pop from the stack. <ahref="../../da/d96/infix__to__postfix2_8c.html#a312e7f6c761a199c1369fbe651e084f0">More...</a><br/></td></tr>
<trclass="memdesc:a653c98c68c558505b75b04c44b7c838e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Function to check whether the stack is empty or not. <ahref="../../da/d96/infix__to__postfix2_8c.html#a653c98c68c558505b75b04c44b7c838e">More...</a><br/></td></tr>
<trclass="memdesc:a2d1c13296ce9c42bb5dd7d834e2802bf"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Function to get top of the stack. <ahref="../../da/d96/infix__to__postfix2_8c.html#a2d1c13296ce9c42bb5dd7d834e2802bf">More...</a><br/></td></tr>
<trclass="memdesc:a02d1bf0ff997efc46ba6fd0ec7952952"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Function to check priority of operators. <ahref="../../da/d96/infix__to__postfix2_8c.html#a02d1bf0ff997efc46ba6fd0ec7952952">More...</a><br/></td></tr>
<trclass="memdesc:ae363a3863a8bfbf40e7a95c2b9dbe71b"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Function to convert infix expression to postfix expression. <ahref="../../da/d96/infix__to__postfix2_8c.html#ae363a3863a8bfbf40e7a95c2b9dbe71b">More...</a><br/></td></tr>
<trclass="memdesc:a791cc5e78425bce611db4e3bdc4b19d5"><tdclass="mdescLeft"> </td><tdclass="mdescRight">global declaration of stack st <br/></td></tr>
<divclass="line"><spanclass="lineno"> 101</span><spanclass="keyword">static</span><spanclass="keywordtype">char</span> post[25]; <spanclass="comment">///< to store the postfix expression</span></div>
<divclass="line"><spanclass="lineno"> 103</span><spanclass="keywordtype">int</span> j = 0; <spanclass="comment">///< keeps track of end of postfix string</span></div>
<divclass="line"><spanclass="lineno"> 104</span><spanclass="keywordflow">for</span>(i = 0; i < strlen(inf); i++) {</div>
<divclass="line"><spanclass="lineno"> 105</span><spanclass="keywordflow">if</span>(isalnum(inf[i])) { <spanclass="comment">// if scanned element is an alphabet or number</span></div>
<divclass="line"><spanclass="lineno"> 106</span> post[j] = inf[i]; <spanclass="comment">// append in postfix expression</span></div>
<divclass="line"><spanclass="lineno"> 109</span><spanclass="keywordflow">else</span><spanclass="keywordflow">if</span>(inf[i] == <spanclass="charliteral">'('</span>) { <spanclass="comment">// if scanned element is opening parentheses</span></div>
<divclass="line"><spanclass="lineno"> 110</span><aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a90e051f23f741be4f8ca86c270d66489">push</a>(inf[i]); <spanclass="comment">// push on stack.</span></div>
<divclass="line"><spanclass="lineno"> 112</span><spanclass="keywordflow">else</span><spanclass="keywordflow">if</span>(inf[i] == <spanclass="charliteral">')'</span>) { <spanclass="comment">// if scanned element is closing parentheses,</span></div>
<divclass="line"><spanclass="lineno"> 113</span><spanclass="keywordflow">while</span>(<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a2d1c13296ce9c42bb5dd7d834e2802bf">Top</a>() != <spanclass="charliteral">'('</span>) { <spanclass="comment">// pop elements from stack and append in postfix expression</span></div>
<divclass="line"><spanclass="lineno"> 119</span><spanclass="keywordflow">else</span> { <spanclass="comment">// if scanned element is an operator</span></div>
<divclass="line"><spanclass="lineno"> 120</span><spanclass="keywordflow">while</span>( (!<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a653c98c68c558505b75b04c44b7c838e">isEmpty</a>()) && (<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a02d1bf0ff997efc46ba6fd0ec7952952">priority</a>(inf[i]) <= <aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a02d1bf0ff997efc46ba6fd0ec7952952">priority</a>(<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a2d1c13296ce9c42bb5dd7d834e2802bf">Top</a>())) ) { <spanclass="comment">// pop and append until stack becomes</span></div>
<divclass="line"><spanclass="lineno"> 121</span> post[j] = <aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a312e7f6c761a199c1369fbe651e084f0">pop</a>(); <spanclass="comment">// empty or priority of top operator</span></div>
<divclass="line"><spanclass="lineno"> 122</span> j++; <spanclass="comment">// becomes smaller than scanned operator</span></div>
<divclass="line"><spanclass="lineno"> 123</span> } <spanclass="comment">// '(' has priority -1</span></div>
<divclass="line"><spanclass="lineno"> 124</span><aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a90e051f23f741be4f8ca86c270d66489">push</a>(inf[i]); <spanclass="comment">// push the scanned operator</span></div>
<divclass="line"><spanclass="lineno"> 127</span><spanclass="keywordflow">while</span>(!<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#a653c98c68c558505b75b04c44b7c838e">isEmpty</a>()) { <spanclass="comment">// pop and append residual operators from stack</span></div>
<divclass="ttc"id="ainfix__to__postfix2_8c_html_a02d1bf0ff997efc46ba6fd0ec7952952"><divclass="ttname"><ahref="../../da/d96/infix__to__postfix2_8c.html#a02d1bf0ff997efc46ba6fd0ec7952952">priority</a></div><divclass="ttdeci">int16_t priority(char opr)</div><divclass="ttdoc">Function to check priority of operators.</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:83</div></div>
<divclass="ttc"id="ainfix__to__postfix2_8c_html_a2d1c13296ce9c42bb5dd7d834e2802bf"><divclass="ttname"><ahref="../../da/d96/infix__to__postfix2_8c.html#a2d1c13296ce9c42bb5dd7d834e2802bf">Top</a></div><divclass="ttdeci">char Top()</div><divclass="ttdoc">Function to get top of the stack.</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:72</div></div>
<divclass="ttc"id="ainfix__to__postfix2_8c_html_a312e7f6c761a199c1369fbe651e084f0"><divclass="ttname"><ahref="../../da/d96/infix__to__postfix2_8c.html#a312e7f6c761a199c1369fbe651e084f0">pop</a></div><divclass="ttdeci">char pop()</div><divclass="ttdoc">Function to pop from the stack.</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:45</div></div>
<divclass="ttc"id="ainfix__to__postfix2_8c_html_a653c98c68c558505b75b04c44b7c838e"><divclass="ttname"><ahref="../../da/d96/infix__to__postfix2_8c.html#a653c98c68c558505b75b04c44b7c838e">isEmpty</a></div><divclass="ttdeci">uint16_t isEmpty()</div><divclass="ttdoc">Function to check whether the stack is empty or not.</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:61</div></div>
<divclass="ttc"id="ainfix__to__postfix2_8c_html_a90e051f23f741be4f8ca86c270d66489"><divclass="ttname"><ahref="../../da/d96/infix__to__postfix2_8c.html#a90e051f23f741be4f8ca86c270d66489">push</a></div><divclass="ttdeci">void push(char opd)</div><divclass="ttdoc">Function to push on the stack.</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:32</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d96/infix__to__postfix2_8c_ae363a3863a8bfbf40e7a95c2b9dbe71b_cgraph.svg"width="195"height="240"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="ttc"id="ainfix__to__postfix2_8c_html_a791cc5e78425bce611db4e3bdc4b19d5"><divclass="ttname"><ahref="../../da/d96/infix__to__postfix2_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a></div><divclass="ttdeci">struct Stack st</div><divclass="ttdoc">global declaration of stack st</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:25</div></div>
<divclass="ttc"id="astruct_stack_html_ad62fb36816185f3eef3a6f735a61f54a"><divclass="ttname"><ahref="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">Stack::top</a></div><divclass="ttdeci">int top</div><divclass="ttdoc">stores index of the top element</div><divclass="ttdef"><b>Definition:</b> infix_to_postfix2.c:23</div></div>
<divclass="line"><spanclass="lineno"> 158</span><aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <spanclass="comment">/// run self-test implementations</span></div>
<divclass="line"><spanclass="lineno"> 159</span><spanclass="keywordtype">char</span> inf[25]; <spanclass="comment">///< to store input infix expression</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d96/infix__to__postfix2_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg"width="386"height="240"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><spanclass="lineno"> 46</span><spanclass="keywordtype">char</span> item; <spanclass="comment">///< to store the popped value to be returned</span></div>
<divclass="line"><spanclass="lineno"> 144</span> assert(strcmp(<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#ae363a3863a8bfbf40e7a95c2b9dbe71b">convert</a>(<spanclass="stringliteral">"(A/(B-C)*D+E)"</span>), <spanclass="stringliteral">"ABC-/D*E+"</span>) == 0); <spanclass="comment">/// this ensures that the algorithm works as expected</span></div>
<divclass="line"><spanclass="lineno"> 148</span> assert(strcmp(<aclass="code hl_function"href="../../da/d96/infix__to__postfix2_8c.html#ae363a3863a8bfbf40e7a95c2b9dbe71b">convert</a>(<spanclass="stringliteral">"7-(2*3+5)*(8-4/2)"</span>), <spanclass="stringliteral">"723*5+842/-*-"</span>) == 0); <spanclass="comment">/// this ensures that the algorithm works as expected</span></div>
<divclass="line"><spanclass="lineno"> 149</span> printf(<spanclass="stringliteral">"All tests have successfully passed!\n"</span>);</div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d96/infix__to__postfix2_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg"width="287"height="240"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<liclass="footer">Generated by <ahref="https://www.doxygen.org/index.html"><imgclass="footer"src="../../doxygen.svg"width="104"height="31"alt="doxygen"/></a> 1.9.3 </li>