TheAlgorithms-C/df/d43/postfix__evaluation_8c.html
2021-10-25 19:34:27 +00:00

394 lines
32 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=11"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: misc/postfix_evaluation.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">&#160;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.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'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:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(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:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('df/d43/postfix__evaluation_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> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a> </div>
<div class="headertitle"><div class="title">postfix_evaluation.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<p><a href="https://www.includehelp.com/c/evaluation-of-postfix-expressions-using-stack-with-c-program.aspx" target="_blank">Postfix evaluation algorithm</a> implementation
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;ctype.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;stdint.h&gt;</code><br />
<code>#include &lt;assert.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for postfix_evaluation.c:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d26/postfix__evaluation_8c__incl.svg" width="524" height="112"><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 id="nested-classes" name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</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">&#160;</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">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:af395c540f7e70a8d82d055a0aa42bbef"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d43/postfix__evaluation_8c.html#af395c540f7e70a8d82d055a0aa42bbef">push</a> (int8_t opd)</td></tr>
<tr class="memdesc:af395c540f7e70a8d82d055a0aa42bbef"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to push on the stack. <a href="../../df/d43/postfix__evaluation_8c.html#af395c540f7e70a8d82d055a0aa42bbef">More...</a><br /></td></tr>
<tr class="separator:af395c540f7e70a8d82d055a0aa42bbef"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8546e4b3f61be1f09ce47f428116ad7d"><td class="memItemLeft" align="right" valign="top">int8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d43/postfix__evaluation_8c.html#a8546e4b3f61be1f09ce47f428116ad7d">pop</a> ()</td></tr>
<tr class="memdesc:a8546e4b3f61be1f09ce47f428116ad7d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to pop from the stack. <a href="../../df/d43/postfix__evaluation_8c.html#a8546e4b3f61be1f09ce47f428116ad7d">More...</a><br /></td></tr>
<tr class="separator:a8546e4b3f61be1f09ce47f428116ad7d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4494492c8fc2509f602acc8228a3b623"><td class="memItemLeft" align="right" valign="top">int8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d43/postfix__evaluation_8c.html#a4494492c8fc2509f602acc8228a3b623">evaluate</a> (char post[])</td></tr>
<tr class="memdesc:a4494492c8fc2509f602acc8228a3b623"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to evaluate postfix expression. <a href="../../df/d43/postfix__evaluation_8c.html#a4494492c8fc2509f602acc8228a3b623">More...</a><br /></td></tr>
<tr class="separator:a4494492c8fc2509f602acc8228a3b623"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d43/postfix__evaluation_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations. <a href="../../df/d43/postfix__evaluation_8c.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d43/postfix__evaluation_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../df/d43/postfix__evaluation_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="var-members" name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a791cc5e78425bce611db4e3bdc4b19d5"><td class="memItemLeft" align="right" valign="top"><a id="a791cc5e78425bce611db4e3bdc4b19d5" name="a791cc5e78425bce611db4e3bdc4b19d5"></a>
struct <a class="el" href="../../dd/d10/struct_stack.html">Stack</a>&#160;</td><td class="memItemRight" valign="bottom"><b>st</b></td></tr>
<tr class="memdesc:a791cc5e78425bce611db4e3bdc4b19d5"><td class="mdescLeft">&#160;</td><td class="mdescRight">global declaration of stack st <br /></td></tr>
<tr class="separator:a791cc5e78425bce611db4e3bdc4b19d5"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p ><a href="https://www.includehelp.com/c/evaluation-of-postfix-expressions-using-stack-with-c-program.aspx" target="_blank">Postfix evaluation algorithm</a> implementation </p>
<p >The input postfix expression is of type string upto 49 characters (including space delimiters). Supported operations- '+', '-', '/', '*', '' </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kumaryash18" target="_blank">Kumar Yash</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a4494492c8fc2509f602acc8228a3b623" name="a4494492c8fc2509f602acc8228a3b623"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4494492c8fc2509f602acc8228a3b623">&#9670;&nbsp;</a></span>evaluate()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int8_t evaluate </td>
<td>(</td>
<td class="paramtype">char&#160;</td>
<td class="paramname"><em>post</em>[]</td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to evaluate postfix expression. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">post</td><td>the input postfix expression </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>evaluated answer </dd></dl>
<div class="fragment"><div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> {</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> int8_t it1;</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> int8_t it2;</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> int8_t temp;</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> int8_t number;</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <span class="keywordtype">int</span> i;</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="keywordflow">for</span>(i = 0; i &lt; strlen(post); i++) {</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> <span class="keywordflow">if</span>(post[i] == <span class="charliteral">&#39; &#39;</span>) {</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> <span class="keywordflow">continue</span>; <span class="comment">// ignore delimiter</span></div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> }</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(isdigit(post[i])) {</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> number = 0;</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <span class="keywordflow">do</span> {</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> number = number * 10 + (post[i]-<span class="charliteral">&#39;0&#39;</span>);</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> i++;</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> } <span class="keywordflow">while</span>(i &lt; strlen(post) &amp;&amp; isdigit(post[i]));</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#af395c540f7e70a8d82d055a0aa42bbef">push</a>(number);</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> }</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> it2 = <a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#a8546e4b3f61be1f09ce47f428116ad7d">pop</a>();</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> it1 = <a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#a8546e4b3f61be1f09ce47f428116ad7d">pop</a>();</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> <span class="keywordflow">switch</span>(post[i]) {</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;+&#39;</span>:</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> temp = it1 + it2; <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;-&#39;</span>:</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> temp = it1 - it2; <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;*&#39;</span>:</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> temp = it1 * it2; <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;/&#39;</span>:</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> temp = it1 / it2; <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;%&#39;</span>:</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> temp = it1 % it2; <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> <span class="keywordflow">default</span>:</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> printf(<span class="stringliteral">&quot;Invalid operator&quot;</span>); exit(1);</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> }</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> <a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#af395c540f7e70a8d82d055a0aa42bbef">push</a>(temp);</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> }</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> }</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#a8546e4b3f61be1f09ce47f428116ad7d">pop</a>();</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span>}</div>
<div class="ttc" id="apostfix__evaluation_8c_html_a8546e4b3f61be1f09ce47f428116ad7d"><div class="ttname"><a href="../../df/d43/postfix__evaluation_8c.html#a8546e4b3f61be1f09ce47f428116ad7d">pop</a></div><div class="ttdeci">int8_t pop()</div><div class="ttdoc">Function to pop from the stack.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.c:44</div></div>
<div class="ttc" id="apostfix__evaluation_8c_html_af395c540f7e70a8d82d055a0aa42bbef"><div class="ttname"><a href="../../df/d43/postfix__evaluation_8c.html#af395c540f7e70a8d82d055a0aa42bbef">push</a></div><div class="ttdeci">void push(int8_t opd)</div><div class="ttdoc">Function to push on the stack.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.c:31</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="../../df/d43/postfix__evaluation_8c_a4494492c8fc2509f602acc8228a3b623_cgraph.svg" width="182" height="88"><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="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&nbsp;</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&#160;</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>
<p >initialize</p>
<p >run self-test implementations</p>
<div class="fragment"><div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> {</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> <a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a> = -1; <span class="comment">/// initialize</span></div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> <a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">/// run self-test implementations</span></div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span>}</div>
<div class="ttc" id="apostfix__evaluation_8c_html_a791cc5e78425bce611db4e3bdc4b19d5"><div class="ttname"><a href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a></div><div class="ttdeci">struct Stack st</div><div class="ttdoc">global declaration of stack st</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.c:24</div></div>
<div class="ttc" id="apostfix__evaluation_8c_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../df/d43/postfix__evaluation_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.c:105</div></div>
<div class="ttc" id="astruct_stack_html_ad62fb36816185f3eef3a6f735a61f54a"><div class="ttname"><a href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">Stack::top</a></div><div class="ttdeci">int top</div><div class="ttdoc">stores index of the top element</div><div class="ttdef"><b>Definition:</b> infix_to_postfix2.c:23</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="../../df/d43/postfix__evaluation_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="372" height="88"><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="a8546e4b3f61be1f09ce47f428116ad7d" name="a8546e4b3f61be1f09ce47f428116ad7d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8546e4b3f61be1f09ce47f428116ad7d">&#9670;&nbsp;</a></span>pop()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int8_t pop </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to pop from the stack. </p>
<dl class="section return"><dt>Returns</dt><dd>popped number </dd></dl>
<p >&lt; to store the popped value to be returned</p>
<div class="fragment"><div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> {</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> int8_t item; <span class="comment">///&lt; to store the popped value to be returned</span></div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> <span class="keywordflow">if</span>(<a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a> == -1) { <span class="comment">// underflow condition</span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> printf(<span class="stringliteral">&quot;Stack underflow...&quot;</span>);</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> exit(1);</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> }</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> item = <a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#a856ca6f4a9ffde43f0cb3b43cb4d044d">stack</a>[<a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a>];</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span> <a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a>--;</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> <span class="keywordflow">return</span> item;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span>}</div>
<div class="ttc" id="astruct_stack_html_a856ca6f4a9ffde43f0cb3b43cb4d044d"><div class="ttname"><a href="../../dd/d10/struct_stack.html#a856ca6f4a9ffde43f0cb3b43cb4d044d">Stack::stack</a></div><div class="ttdeci">char stack[10]</div><div class="ttdoc">array stack</div><div class="ttdef"><b>Definition:</b> infix_to_postfix2.c:22</div></div>
</div><!-- fragment -->
</div>
</div>
<a id="af395c540f7e70a8d82d055a0aa42bbef" name="af395c540f7e70a8d82d055a0aa42bbef"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af395c540f7e70a8d82d055a0aa42bbef">&#9670;&nbsp;</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">int8_t&#160;</td>
<td class="paramname"><em>opd</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to push on the stack. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">opd</td><td>number to be pushed in the stack </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> {</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> <span class="keywordflow">if</span>(<a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a> == 19) { <span class="comment">// overflow condition</span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> printf(<span class="stringliteral">&quot;Stack overflow...&quot;</span>);</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> exit(1);</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> }</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> <a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a>++;</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> <a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#a856ca6f4a9ffde43f0cb3b43cb4d044d">stack</a>[<a class="code hl_variable" href="../../df/d43/postfix__evaluation_8c.html#a791cc5e78425bce611db4e3bdc4b19d5">st</a>.<a class="code hl_variable" href="../../dd/d10/struct_stack.html#ad62fb36816185f3eef3a6f735a61f54a">top</a>] = opd;</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">&#9670;&nbsp;</a></span>test()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void test </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Self-test implementations. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<p >this ensures that the algorithm works as expected</p>
<p >this ensures that the algorithm works as expected</p>
<div class="fragment"><div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> {</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <span class="comment">/* check sample test case</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span><span class="comment"> input: &quot;2 10 + 9 6 - /&quot;</span></div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span><span class="comment"> expected output: 4</span></div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span><span class="comment"> */</span></div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> <span class="keywordtype">char</span> temp1[50] = <span class="stringliteral">&quot;2 10 + 9 6 - /&quot;</span>;</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> assert(<a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#a4494492c8fc2509f602acc8228a3b623">evaluate</a>(temp1) == 4); <span class="comment">/// this ensures that the algorithm works as expected</span></div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <span class="comment">/* input: &quot;4 2 + 3 5 1 - * +&quot;</span></div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span><span class="comment"> expected output: 18</span></div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span><span class="comment"> */</span></div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> <span class="keywordtype">char</span> temp2[50] = <span class="stringliteral">&quot;4 2 + 3 5 1 - * +&quot;</span>;</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> assert(<a class="code hl_function" href="../../df/d43/postfix__evaluation_8c.html#a4494492c8fc2509f602acc8228a3b623">evaluate</a>(temp2) == 18); <span class="comment">/// this ensures that the algorithm works as expected</span></div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> printf(<span class="stringliteral">&quot;All tests have successfully passed!\n&quot;</span>);</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span>}</div>
<div class="ttc" id="apostfix__evaluation_8c_html_a4494492c8fc2509f602acc8228a3b623"><div class="ttname"><a href="../../df/d43/postfix__evaluation_8c.html#a4494492c8fc2509f602acc8228a3b623">evaluate</a></div><div class="ttdeci">int8_t evaluate(char post[])</div><div class="ttdoc">Function to evaluate postfix expression.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.c:60</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="../../df/d43/postfix__evaluation_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="274" height="88"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</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_a52f4d3d586a58b02f3a4ddf0a992157.html">misc</a></li><li class="navelem"><a class="el" href="../../df/d43/postfix__evaluation_8c.html">postfix_evaluation.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.2 </li>
</ul>
</div>
</body>
</html>