mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
538 lines
42 KiB
HTML
538 lines
42 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.9.1"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: conversions/infix_to_postfix.c File Reference</title>
|
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../jquery.js"></script>
|
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../resize.js"></script>
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
<script type="text/javascript" src="../../navtree.js"></script>
|
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
|
<script type="text/javascript" src="../../search/search.js"></script>
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
|
jax: ["input/TeX","output/HTML-CSS"],
|
|
});
|
|
</script>
|
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">Algorithms_in_C
|
|
 <span id="projectnumber">1.0.0</span>
|
|
</div>
|
|
<div id="projectbrief">Set of algorithms implemented in C.</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.1 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="../../menudata.js"></script>
|
|
<script type="text/javascript" src="../../menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(function(){initNavTree('db/d0c/infix__to__postfix_8c.html','../../'); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#nested-classes">Data Structures</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle">
|
|
<div class="title">infix_to_postfix.c File Reference</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p><a href="https://condor.depaul.edu/ichu/csc415/notes/notes9/Infix.htm">Infix to Postfix</a> Expression Conversion
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <stdio.h></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for infix_to_postfix.c:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dc/dc9/infix__to__postfix_8c__incl.svg" width="150" height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
</div><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
|
|
Data Structures</h2></td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d10/struct_stack.html">Stack</a></td></tr>
|
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">for printf() and scanf() <a href="../../dd/d10/struct_stack.html#details">More...</a><br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:a613462735d30cae1b85b606ecab30554"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">push</a> (struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a> *p, char x)</td></tr>
|
|
<tr class="memdesc:a613462735d30cae1b85b606ecab30554"><td class="mdescLeft"> </td><td class="mdescRight">push function <a href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">More...</a><br /></td></tr>
|
|
<tr class="separator:a613462735d30cae1b85b606ecab30554"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a940cdcd27c40699eebb4ef113b2d9451"><td class="memItemLeft" align="right" valign="top">char </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#a940cdcd27c40699eebb4ef113b2d9451">pop</a> (struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a> *p)</td></tr>
|
|
<tr class="memdesc:a940cdcd27c40699eebb4ef113b2d9451"><td class="mdescLeft"> </td><td class="mdescRight">pop function <a href="../../db/d0c/infix__to__postfix_8c.html#a940cdcd27c40699eebb4ef113b2d9451">More...</a><br /></td></tr>
|
|
<tr class="separator:a940cdcd27c40699eebb4ef113b2d9451"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:afd8245c04b202240390de23170f72d6b"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#afd8245c04b202240390de23170f72d6b">isOprnd</a> (char ch)</td></tr>
|
|
<tr class="memdesc:afd8245c04b202240390de23170f72d6b"><td class="mdescLeft"> </td><td class="mdescRight">isOprnd function <a href="../../db/d0c/infix__to__postfix_8c.html#afd8245c04b202240390de23170f72d6b">More...</a><br /></td></tr>
|
|
<tr class="separator:afd8245c04b202240390de23170f72d6b"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:afa8471c76bc57b12ad21de22beb39021"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#afa8471c76bc57b12ad21de22beb39021">isEmpty</a> (struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a> s)</td></tr>
|
|
<tr class="memdesc:afa8471c76bc57b12ad21de22beb39021"><td class="mdescLeft"> </td><td class="mdescRight">isEmpty function <a href="../../db/d0c/infix__to__postfix_8c.html#afa8471c76bc57b12ad21de22beb39021">More...</a><br /></td></tr>
|
|
<tr class="separator:afa8471c76bc57b12ad21de22beb39021"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ac91f38ad7885fca93e39325361a5c787"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#ac91f38ad7885fca93e39325361a5c787">getPrecedence</a> (char op1, char op2)</td></tr>
|
|
<tr class="memdesc:ac91f38ad7885fca93e39325361a5c787"><td class="mdescLeft"> </td><td class="mdescRight">getPrecedence function returns the precedence after comparing two operators passed as parameter. <a href="../../db/d0c/infix__to__postfix_8c.html#ac91f38ad7885fca93e39325361a5c787">More...</a><br /></td></tr>
|
|
<tr class="separator:ac91f38ad7885fca93e39325361a5c787"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a92af69ffc1e1f965ebce6a44672e96b1"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#a92af69ffc1e1f965ebce6a44672e96b1">convert</a> (char infix[], char postfix[])</td></tr>
|
|
<tr class="memdesc:a92af69ffc1e1f965ebce6a44672e96b1"><td class="mdescLeft"> </td><td class="mdescRight">convert function <a href="../../db/d0c/infix__to__postfix_8c.html#a92af69ffc1e1f965ebce6a44672e96b1">More...</a><br /></td></tr>
|
|
<tr class="separator:a92af69ffc1e1f965ebce6a44672e96b1"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">main function <a href="../../db/d0c/infix__to__postfix_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p><a href="https://condor.depaul.edu/ichu/csc415/notes/notes9/Infix.htm">Infix to Postfix</a> Expression Conversion </p>
|
|
<p>Convert Infixed expressions to Postfix expression. </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/harshcut">Harsh Karande</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a92af69ffc1e1f965ebce6a44672e96b1"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a92af69ffc1e1f965ebce6a44672e96b1">◆ </a></span>convert()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void convert </td>
|
|
<td>(</td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>infix</em>[], </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>postfix</em>[] </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>convert function </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">infix[]</td><td>: infix array provided by user </td></tr>
|
|
<tr><td class="paramname">postfix[]</td><td>: empty array to be given to <a class="el" href="../../db/d0c/infix__to__postfix_8c.html#a92af69ffc1e1f965ebce6a44672e96b1" title="convert function">convert()</a> </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>postfixed expresion or \0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00131"></a><span class="lineno"> 131</span> {</div>
|
|
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keyword">struct </span><a class="code" href="../../dd/d10/struct_stack.html">Stack</a> s; <span class="comment">// initialze object reference of stack</span></div>
|
|
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  s.<a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a> = -1; <span class="comment">// initalize the tos</span></div>
|
|
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  </div>
|
|
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="keywordtype">int</span> i, j = 0, pr;</div>
|
|
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  <span class="keywordtype">char</span> ch, temp;</div>
|
|
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  </div>
|
|
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <span class="keywordflow">for</span> (i = 0; infix[i] != <span class="charliteral">'\0'</span>; i++)</div>
|
|
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  {</div>
|
|
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  ch = infix[i];</div>
|
|
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  </div>
|
|
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  <span class="keywordflow">if</span> (<a class="code" href="../../db/d0c/infix__to__postfix_8c.html#afd8245c04b202240390de23170f72d6b">isOprnd</a>(ch) == 1) <span class="comment">// check if char is operand or operator</span></div>
|
|
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  {</div>
|
|
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  postfix[j] = ch; <span class="comment">// assign ch to postfix array with index j</span></div>
|
|
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  j++; <span class="comment">// incement j</span></div>
|
|
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  }</div>
|
|
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  {</div>
|
|
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="keywordflow">if</span> (ch == <span class="charliteral">'('</span>)</div>
|
|
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  {</div>
|
|
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">push</a>(&s, ch);</div>
|
|
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  }</div>
|
|
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  {</div>
|
|
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="keywordflow">if</span> (ch == <span class="charliteral">')'</span>)</div>
|
|
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  {</div>
|
|
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  <span class="keywordflow">while</span> ((temp = <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#a940cdcd27c40699eebb4ef113b2d9451">pop</a>(&s)) != <span class="charliteral">'('</span>)</div>
|
|
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  {</div>
|
|
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  postfix[j] = temp;</div>
|
|
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  j++;</div>
|
|
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  }</div>
|
|
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  }</div>
|
|
<div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  {</div>
|
|
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  <span class="keywordflow">while</span> (<a class="code" href="../../db/d0c/infix__to__postfix_8c.html#afa8471c76bc57b12ad21de22beb39021">isEmpty</a>(s) == 0) <span class="comment">// check if stack is empty</span></div>
|
|
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  {</div>
|
|
<div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  pr = <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#ac91f38ad7885fca93e39325361a5c787">getPrecedence</a> (ch,</div>
|
|
<div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  s.arr[s.tos]); <span class="comment">// check operator precedence</span></div>
|
|
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  </div>
|
|
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  <span class="keywordflow">if</span> (pr == 1)</div>
|
|
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  {</div>
|
|
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  <span class="keywordflow">break</span>; <span class="comment">// if ch has a greater precedence than</span></div>
|
|
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  <span class="comment">// s.arr[s.top]</span></div>
|
|
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  }</div>
|
|
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  </div>
|
|
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  postfix[j] = <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#a940cdcd27c40699eebb4ef113b2d9451">pop</a>(&s);</div>
|
|
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  j++;</div>
|
|
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  }</div>
|
|
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  </div>
|
|
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">push</a>(&s, ch); <span class="comment">// push ch to stack</span></div>
|
|
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  }</div>
|
|
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  }</div>
|
|
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  }</div>
|
|
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  }</div>
|
|
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  </div>
|
|
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  <span class="keywordflow">while</span> (<a class="code" href="../../db/d0c/infix__to__postfix_8c.html#afa8471c76bc57b12ad21de22beb39021">isEmpty</a>(s) == 0) <span class="comment">// check if stack is empty</span></div>
|
|
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  {</div>
|
|
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  postfix[j] = <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#a940cdcd27c40699eebb4ef113b2d9451">pop</a>(&s);</div>
|
|
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  j++;</div>
|
|
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  }</div>
|
|
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  </div>
|
|
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  postfix[j] = <span class="charliteral">'\0'</span>;</div>
|
|
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span> }</div>
|
|
<div class="ttc" id="ainfix__to__postfix_8c_html_a613462735d30cae1b85b606ecab30554"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#a613462735d30cae1b85b606ecab30554">push</a></div><div class="ttdeci">void push(struct Stack *p, char ch)</div><div class="ttdoc">push function</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:55</div></div>
|
|
<div class="ttc" id="ainfix__to__postfix_8c_html_a940cdcd27c40699eebb4ef113b2d9451"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#a940cdcd27c40699eebb4ef113b2d9451">pop</a></div><div class="ttdeci">char pop(struct Stack *p)</div><div class="ttdoc">pop function</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:72</div></div>
|
|
<div class="ttc" id="ainfix__to__postfix_8c_html_ac91f38ad7885fca93e39325361a5c787"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#ac91f38ad7885fca93e39325361a5c787">getPrecedence</a></div><div class="ttdeci">int getPrecedence(char op1, char op2)</div><div class="ttdoc">getPrecedence function returns the precedence after comparing two operators passed as parameter.</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:201</div></div>
|
|
<div class="ttc" id="ainfix__to__postfix_8c_html_afa8471c76bc57b12ad21de22beb39021"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#afa8471c76bc57b12ad21de22beb39021">isEmpty</a></div><div class="ttdeci">int isEmpty(struct Stack s)</div><div class="ttdoc">isEmpty function</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:112</div></div>
|
|
<div class="ttc" id="ainfix__to__postfix_8c_html_afd8245c04b202240390de23170f72d6b"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#afd8245c04b202240390de23170f72d6b">isOprnd</a></div><div class="ttdeci">int isOprnd(char ch)</div><div class="ttdoc">isOprnd function</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:93</div></div>
|
|
<div class="ttc" id="astruct_stack_html"><div class="ttname"><a href="../../dd/d10/struct_stack.html">Stack</a></div><div class="ttdoc">for printf() and scanf()</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:18</div></div>
|
|
<div class="ttc" id="astruct_stack_html_ac2dbef151bc913684a90b06836725ef9"><div class="ttname"><a href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">Stack::tos</a></div><div class="ttdeci">int tos</div><div class="ttdoc">static array of integers</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:20</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/d0c/infix__to__postfix_8c_a92af69ffc1e1f965ebce6a44672e96b1_cgraph.svg" width="234" height="240"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ac91f38ad7885fca93e39325361a5c787"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ac91f38ad7885fca93e39325361a5c787">◆ </a></span>getPrecedence()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int getPrecedence </td>
|
|
<td>(</td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>op1</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>op2</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>getPrecedence function returns the precedence after comparing two operators passed as parameter. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">op1</td><td>: first operator </td></tr>
|
|
<tr><td class="paramname">op2</td><td>: second operator </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>1 or 0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00202"></a><span class="lineno"> 202</span> {</div>
|
|
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  <span class="keywordflow">if</span> (op2 == <span class="charliteral">'$'</span>)</div>
|
|
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  {</div>
|
|
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  }</div>
|
|
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (op1 == <span class="charliteral">'$'</span>)</div>
|
|
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  {</div>
|
|
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  }</div>
|
|
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (op2 == <span class="charliteral">'*'</span> || op2 == <span class="charliteral">'/'</span> || op2 == <span class="charliteral">'%'</span>)</div>
|
|
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  {</div>
|
|
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  }</div>
|
|
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (op1 == <span class="charliteral">'*'</span> || op1 == <span class="charliteral">'/'</span> || op1 == <span class="charliteral">'%'</span>)</div>
|
|
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  {</div>
|
|
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  }</div>
|
|
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (op2 == <span class="charliteral">'+'</span> || op2 == <span class="charliteral">'-'</span>)</div>
|
|
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  {</div>
|
|
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  }</div>
|
|
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  {</div>
|
|
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  }</div>
|
|
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="afa8471c76bc57b12ad21de22beb39021"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#afa8471c76bc57b12ad21de22beb39021">◆ </a></span>isEmpty()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int isEmpty </td>
|
|
<td>(</td>
|
|
<td class="paramtype">struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a> </td>
|
|
<td class="paramname"><em>s</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>isEmpty function </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">s</td><td>: it is the object reference of stack </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>1 or 0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> {</div>
|
|
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="keywordflow">if</span> (s.<a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a> == -1) <span class="comment">// check if stack is empty</span></div>
|
|
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  {</div>
|
|
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="keywordflow">return</span> 1; <span class="comment">// return for true result</span></div>
|
|
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  }</div>
|
|
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  {</div>
|
|
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="keywordflow">return</span> 0; <span class="comment">// return for false result</span></div>
|
|
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  }</div>
|
|
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="afd8245c04b202240390de23170f72d6b"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#afd8245c04b202240390de23170f72d6b">◆ </a></span>isOprnd()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int isOprnd </td>
|
|
<td>(</td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>ch</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>isOprnd function </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">ch</td><td>: this is the element from the infix array </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>1 or 0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00094"></a><span class="lineno"> 94</span> {</div>
|
|
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="keywordflow">if</span> ((ch >= 65 && ch <= 90) ||</div>
|
|
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  (ch >= 97 && ch <= 122) || <span class="comment">// check if ch is an operator or</span></div>
|
|
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  (ch >= 48 && ch <= 57)) <span class="comment">// operand using ASCII values</span></div>
|
|
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  {</div>
|
|
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="keywordflow">return</span> 1; <span class="comment">// return for true result</span></div>
|
|
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  }</div>
|
|
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  {</div>
|
|
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">return</span> 0; <span class="comment">// return for false result</span></div>
|
|
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  }</div>
|
|
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>main function </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> {</div>
|
|
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  <span class="keywordtype">char</span> infix[20], postfix[20]; <span class="comment">// initialize empty infix and postfix array</span></div>
|
|
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  </div>
|
|
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  printf(<span class="stringliteral">"Enter infix expression: "</span>); <span class="comment">// example : A+B-C*D/E$F</span></div>
|
|
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  scanf(<span class="stringliteral">"%s"</span>, infix); <span class="comment">// get values for infix array</span></div>
|
|
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  </div>
|
|
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <a class="code" href="../../db/d0c/infix__to__postfix_8c.html#a92af69ffc1e1f965ebce6a44672e96b1">convert</a>(infix, postfix);</div>
|
|
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  printf(<span class="stringliteral">"Postfix expression is %s"</span>, postfix); <span class="comment">// output : AB+CD*EF$/-</span></div>
|
|
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  </div>
|
|
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span> }</div>
|
|
<div class="ttc" id="ainfix__to__postfix_8c_html_a92af69ffc1e1f965ebce6a44672e96b1"><div class="ttname"><a href="../../db/d0c/infix__to__postfix_8c.html#a92af69ffc1e1f965ebce6a44672e96b1">convert</a></div><div class="ttdeci">void convert(char infix[], char postfix[])</div><div class="ttdoc">convert function</div><div class="ttdef"><b>Definition:</b> infix_to_postfix.c:130</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/d0c/infix__to__postfix_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="332" height="240"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a940cdcd27c40699eebb4ef113b2d9451"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a940cdcd27c40699eebb4ef113b2d9451">◆ </a></span>pop()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int pop </td>
|
|
<td>(</td>
|
|
<td class="paramtype">struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a> * </td>
|
|
<td class="paramname"><em>p</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>pop function </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">*p</td><td>: used as a pointer variable of stack </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>x or \0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00073"></a><span class="lineno"> 73</span> {</div>
|
|
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  <span class="keywordtype">char</span> x;</div>
|
|
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  </div>
|
|
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">if</span> (p-><a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a> == -1)</div>
|
|
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  {</div>
|
|
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  printf(<span class="stringliteral">"Stack Underflow!"</span>);</div>
|
|
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <span class="keywordflow">return</span> <span class="charliteral">'\0'</span>;</div>
|
|
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  }</div>
|
|
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  </div>
|
|
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  x = p->arr[p-><a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a>]; <span class="comment">// assign the value of stack at index tos to x</span></div>
|
|
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  p-><a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a> -= 1; <span class="comment">// decrement tos</span></div>
|
|
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  </div>
|
|
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordflow">return</span> x;</div>
|
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a613462735d30cae1b85b606ecab30554"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a613462735d30cae1b85b606ecab30554">◆ </a></span>push()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void push </td>
|
|
<td>(</td>
|
|
<td class="paramtype">struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a> * </td>
|
|
<td class="paramname"><em>p</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">char </td>
|
|
<td class="paramname"><em>x</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>push function </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">*p</td><td>: used as a pointer variable of stack </td></tr>
|
|
<tr><td class="paramname">x</td><td>: char to be pushed in stack </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> {</div>
|
|
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <span class="keywordflow">if</span> (p-><a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a> == 9) <span class="comment">// check if stack has reached its max limit</span></div>
|
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  {</div>
|
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  printf(<span class="stringliteral">"Stack Overflow!"</span>);</div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  }</div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  </div>
|
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  p-><a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a> += 1; <span class="comment">// increment tos</span></div>
|
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  p->arr[p-><a class="code" href="../../dd/d10/struct_stack.html#ac2dbef151bc913684a90b06836725ef9">tos</a>] = x; <span class="comment">// assign char x to index of stack pointed by tos</span></div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="../../dir_9babc524d57e25f3d9f4179cabc3599e.html">conversions</a></li><li class="navelem"><a class="el" href="../../db/d0c/infix__to__postfix_8c.html">infix_to_postfix.c</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|