Files
C-Plus-Plus/d7/d75/postfix__evaluation_8cpp.html
2025-09-10 03:15:07 +00:00

502 lines
38 KiB
HTML

<!-- HTML header for doxygen 1.12.0-->
<!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" lang="en-US">
<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.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TheAlgorithms/C++: others/postfix_evaluation.cpp File Reference</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<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>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript" src="../../cookie.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/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.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 id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('../../',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
</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">
$(function(){initNavTree('d7/d75/postfix__evaluation_8cpp.html','../../',''); });
</script>
<div id="container">
<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">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">postfix_evaluation.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Evaluation of <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Postfix Expression</a>
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;algorithm&gt;</code><br />
<code>#include &lt;array&gt;</code><br />
<code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
<code>#include &lt;stack&gt;</code><br />
<code>#include &lt;string&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for postfix_evaluation.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" loading="lazy" frameborder="0" src="../../d5/dc8/postfix__evaluation_8cpp__incl.svg" width="499" height="111"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
<p><a href="../../d7/d75/postfix__evaluation_8cpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 id="header-namespaces" class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:others" id="r_others"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d6f/namespaceothers.html">others</a></td></tr>
<tr class="memdesc:d0/d6f/namespaceothers"><td class="mdescLeft">&#160;</td><td class="mdescRight">for <span class="tt">vector</span> <br /></td></tr>
<tr class="memitem:postfix_5Fexpression" id="r_postfix_5Fexpression"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/de6/namespacepostfix__expression.html">postfix_expression</a></td></tr>
<tr class="memdesc:d4/de6/namespacepostfix__expression"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for Postfix Expression algorithm. <br /></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 id="header-func-members" class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a4c27f949c9d6659be9f5bd2ccbe1360a" id="r_a4c27f949c9d6659be9f5bd2ccbe1360a"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a4c27f949c9d6659be9f5bd2ccbe1360a">others::postfix_expression::is_number</a> (const std::string &amp;s)</td></tr>
<tr class="memdesc:a4c27f949c9d6659be9f5bd2ccbe1360a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Checks if scanned string is a number. <br /></td></tr>
<tr class="memitem:a19d995518723c1bc69718c3c33381e30" id="r_a19d995518723c1bc69718c3c33381e30"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a19d995518723c1bc69718c3c33381e30">others::postfix_expression::evaluate</a> (float a, float b, const std::string &amp;operation, std::stack&lt; float &gt; &amp;<a class="el" href="../../d1/dc2/classstack.html">stack</a>)</td></tr>
<tr class="memdesc:a19d995518723c1bc69718c3c33381e30"><td class="mdescLeft">&#160;</td><td class="mdescRight">Evaluate answer using given last two operands from and operation. <br /></td></tr>
<tr class="memitem:ae38bd3a177a6d61da3859a281233bbe1" id="r_ae38bd3a177a6d61da3859a281233bbe1"><td class="memTemplParams" colspan="2">template&lt;std::size_t N&gt; </td></tr>
<tr class="memitem:ae38bd3a177a6d61da3859a281233bbe1 template"><td class="memItemLeft" align="right" valign="top">float&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a> (std::array&lt; std::string, N &gt; input)</td></tr>
<tr class="memdesc:ae38bd3a177a6d61da3859a281233bbe1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Postfix Evaluation algorithm to compute the value from given input array. <br /></td></tr>
<tr class="memitem:a6a8eeb7d346d5cd6335d9780fb7c0f15" id="r_a6a8eeb7d346d5cd6335d9780fb7c0f15"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a6a8eeb7d346d5cd6335d9780fb7c0f15">test_function_1</a> ()</td></tr>
<tr class="memdesc:a6a8eeb7d346d5cd6335d9780fb7c0f15"><td class="mdescLeft">&#160;</td><td class="mdescRight">Test function 1 with input array {'2', '3', '1', '*', '+', '9', '-'}. <br /></td></tr>
<tr class="memitem:a5b97d12e8b61484f756a8721992bfae1" id="r_a5b97d12e8b61484f756a8721992bfae1"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a5b97d12e8b61484f756a8721992bfae1">test_function_2</a> ()</td></tr>
<tr class="memdesc:a5b97d12e8b61484f756a8721992bfae1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Test function 2 with input array {'100', '200', '+', '2', '/', '5', '*', '7', '+'}. <br /></td></tr>
<tr class="memitem:a29c6172e7ccef1d93c1d116f407928dc" id="r_a29c6172e7ccef1d93c1d116f407928dc"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a29c6172e7ccef1d93c1d116f407928dc">test_function_3</a> ()</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4" id="r_ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
</table>
<a name="details" id="details"></a><h2 id="header-details" class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Evaluation of <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Postfix Expression</a> </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/Darshana-Sarma" target="_blank">Darshana Sarma</a></dd></dl>
<p>Create a stack to store operands (or values). Scan the given expression and do following for every scanned element. If the element is a number, push it into the stack If the element is a operator, pop operands for the operator from stack. Evaluate the operator and push the result back to the stack When the expression is ended, the number in the stack is the final answer </p>
<p class="definition">Definition in file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
</div><a name="doc-func-members" id="doc-func-members"></a><h2 id="header-doc-func-members" class="groupheader">Function Documentation</h2>
<a id="a19d995518723c1bc69718c3c33381e30" name="a19d995518723c1bc69718c3c33381e30"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a19d995518723c1bc69718c3c33381e30">&#9670;&#160;</a></span>evaluate()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void others::postfix_expression::evaluate </td>
<td>(</td>
<td class="paramtype">float</td> <td class="paramname"><span class="paramname"><em>a</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float</td> <td class="paramname"><span class="paramname"><em>b</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const std::string &amp;</td> <td class="paramname"><span class="paramname"><em>operation</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">std::stack&lt; float &gt; &amp;</td> <td class="paramname"><span class="paramname"><em>stack</em></span>&#160;)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Evaluate answer using given last two operands from and operation. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">a</td><td>second last added operand which will be used for evaluation </td></tr>
<tr><td class="paramname">b</td><td>last added operand which will be used for evaluation </td></tr>
<tr><td class="paramname">operation</td><td>to be performed with respective floats </td></tr>
<tr><td class="paramname">stack</td><td>containing numbers </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>none </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00049">49</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 50</span> {</div>
<div class="line"><span class="lineno"> 51</span> <span class="keywordtype">float</span> c = 0;</div>
<div class="line"><span class="lineno"> 52</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *op = operation.c_str();</div>
<div class="line"><span class="lineno"> 53</span> <span class="keywordflow">switch</span> (*op) {</div>
<div class="line"><span class="lineno"> 54</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;+&#39;</span>:</div>
<div class="line"><span class="lineno"> 55</span> c = a + b; <span class="comment">// Addition of numbers</span></div>
<div class="line"><span class="lineno"> 56</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a90df277532c23519aa7ac3c08ed90a1d">push</a>(c);</div>
<div class="line"><span class="lineno"> 57</span> <span class="keywordflow">break</span>;</div>
<div class="line"><span class="lineno"> 58</span> </div>
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;-&#39;</span>:</div>
<div class="line"><span class="lineno"> 60</span> c = a - b; <span class="comment">// Subtraction of numbers</span></div>
<div class="line"><span class="lineno"> 61</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a90df277532c23519aa7ac3c08ed90a1d">push</a>(c);</div>
<div class="line"><span class="lineno"> 62</span> <span class="keywordflow">break</span>;</div>
<div class="line"><span class="lineno"> 63</span> </div>
<div class="line"><span class="lineno"> 64</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;*&#39;</span>:</div>
<div class="line"><span class="lineno"> 65</span> c = a * b; <span class="comment">// Multiplication of numbers</span></div>
<div class="line"><span class="lineno"> 66</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a90df277532c23519aa7ac3c08ed90a1d">push</a>(c);</div>
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">break</span>;</div>
<div class="line"><span class="lineno"> 68</span> </div>
<div class="line"><span class="lineno"> 69</span> <span class="keywordflow">case</span> <span class="charliteral">&#39;/&#39;</span>:</div>
<div class="line"><span class="lineno"> 70</span> c = a / b; <span class="comment">// Division of numbers</span></div>
<div class="line"><span class="lineno"> 71</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a90df277532c23519aa7ac3c08ed90a1d">push</a>(c);</div>
<div class="line"><span class="lineno"> 72</span> <span class="keywordflow">break</span>;</div>
<div class="line"><span class="lineno"> 73</span> </div>
<div class="line"><span class="lineno"> 74</span> <span class="keywordflow">default</span>:</div>
<div class="line"><span class="lineno"> 75</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Operator not defined\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 76</span> <span class="keywordflow">break</span>;</div>
<div class="line"><span class="lineno"> 77</span> }</div>
<div class="line"><span class="lineno"> 78</span>}</div>
<div class="ttc" id="aclassstack_html"><div class="ttname"><a href="../../d1/dc2/classstack.html">stack</a></div><div class="ttdoc">for std::invalid_argument</div><div class="ttdef"><b>Definition</b> <a href="../../df/d47/stack_8hpp_source.html#l00019">stack.hpp:19</a></div></div>
<div class="ttc" id="aclassstack_html_a90df277532c23519aa7ac3c08ed90a1d"><div class="ttname"><a href="../../d1/dc2/classstack.html#a90df277532c23519aa7ac3c08ed90a1d">stack::push</a></div><div class="ttdeci">void push(const value_type &amp;item)</div><div class="ttdef"><b>Definition</b> <a href="../../df/d47/stack_8hpp_source.html#l00047">stack.hpp:47</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a4c27f949c9d6659be9f5bd2ccbe1360a" name="a4c27f949c9d6659be9f5bd2ccbe1360a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4c27f949c9d6659be9f5bd2ccbe1360a">&#9670;&#160;</a></span>is_number()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool others::postfix_expression::is_number </td>
<td>(</td>
<td class="paramtype">const std::string &amp;</td> <td class="paramname"><span class="paramname"><em>s</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Checks if scanned string is a number. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">s</td><td>scanned string </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>bool boolean value if string is number </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00037">37</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 37</span> {</div>
<div class="line"><span class="lineno"> 38</span> <span class="keywordflow">return</span> !s.empty() &amp;&amp; std::all_of(s.begin(), s.end(), ::isdigit);</div>
<div class="line"><span class="lineno"> 39</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</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"><span class="paramname"><em></em></span></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 class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00156">156</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 156</span> {</div>
<div class="line"><span class="lineno"> 157</span> <a class="code hl_function" href="#a6a8eeb7d346d5cd6335d9780fb7c0f15">test_function_1</a>();</div>
<div class="line"><span class="lineno"> 158</span> <a class="code hl_function" href="#a5b97d12e8b61484f756a8721992bfae1">test_function_2</a>();</div>
<div class="line"><span class="lineno"> 159</span> test_function_3();</div>
<div class="line"><span class="lineno"> 160</span> </div>
<div class="line"><span class="lineno"> 161</span> std::cout &lt;&lt; <span class="stringliteral">&quot;\nTest implementations passed!\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 162</span> </div>
<div class="line"><span class="lineno"> 163</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 164</span>}</div>
<div class="ttc" id="apostfix__evaluation_8cpp_html_a5b97d12e8b61484f756a8721992bfae1"><div class="ttname"><a href="#a5b97d12e8b61484f756a8721992bfae1">test_function_2</a></div><div class="ttdeci">static void test_function_2()</div><div class="ttdoc">Test function 2 with input array {&#39;100&#39;, &#39;200&#39;, &#39;+&#39;, &#39;2&#39;, &#39;/&#39;, &#39;5&#39;, &#39;*&#39;, &#39;7&#39;, &#39;+&#39;}...</div><div class="ttdef"><b>Definition</b> <a href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00133">postfix_evaluation.cpp:133</a></div></div>
<div class="ttc" id="apostfix__evaluation_8cpp_html_a6a8eeb7d346d5cd6335d9780fb7c0f15"><div class="ttname"><a href="#a6a8eeb7d346d5cd6335d9780fb7c0f15">test_function_1</a></div><div class="ttdeci">static void test_function_1()</div><div class="ttdoc">Test function 1 with input array {&#39;2&#39;, &#39;3&#39;, &#39;1&#39;, &#39;*&#39;, &#39;+&#39;, &#39;9&#39;, &#39;-&#39;}.</div><div class="ttdef"><b>Definition</b> <a href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00120">postfix_evaluation.cpp:120</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="ae38bd3a177a6d61da3859a281233bbe1" name="ae38bd3a177a6d61da3859a281233bbe1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae38bd3a177a6d61da3859a281233bbe1">&#9670;&#160;</a></span>postfix_evaluation()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;std::size_t N&gt; </div>
<table class="memname">
<tr>
<td class="memname">float others::postfix_expression::postfix_evaluation </td>
<td>(</td>
<td class="paramtype">std::array&lt; std::string, N &gt;</td> <td class="paramname"><span class="paramname"><em>input</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Postfix Evaluation algorithm to compute the value from given input array. </p>
<dl class="tparams"><dt>Template Parameters</dt><dd>
<table class="tparams">
<tr><td class="paramname">N</td><td>number of array size </td></tr>
</table>
</dd>
</dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">input</td><td>Array of characters consisting of numbers and operations </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>stack[stackTop] returns the top value from the stack </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00088">88</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 88</span> {</div>
<div class="line"><span class="lineno"> 89</span> std::stack&lt;float&gt; <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>;</div>
<div class="line"><span class="lineno"> 90</span> <span class="keywordtype">int</span> j = 0;</div>
<div class="line"><span class="lineno"> 91</span> </div>
<div class="line"><span class="lineno"> 92</span> <span class="keywordflow">while</span> (j &lt; N) {</div>
<div class="line"><span class="lineno"> 93</span> std::string scan = input[j];</div>
<div class="line"><span class="lineno"> 94</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="#a4c27f949c9d6659be9f5bd2ccbe1360a">is_number</a>(scan)) {</div>
<div class="line"><span class="lineno"> 95</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a90df277532c23519aa7ac3c08ed90a1d">push</a>(std::stof(scan));</div>
<div class="line"><span class="lineno"> 96</span> </div>
<div class="line"><span class="lineno"> 97</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><span class="lineno"> 98</span> <span class="keyword">const</span> <span class="keywordtype">float</span> op2 = <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#ae09630c4384903d187801921b2ddc709">top</a>();</div>
<div class="line"><span class="lineno"> 99</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a3647fb4418890f19e0dc414b8092b8b0">pop</a>();</div>
<div class="line"><span class="lineno"> 100</span> <span class="keyword">const</span> <span class="keywordtype">float</span> op1 = <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#ae09630c4384903d187801921b2ddc709">top</a>();</div>
<div class="line"><span class="lineno"> 101</span> <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#a3647fb4418890f19e0dc414b8092b8b0">pop</a>();</div>
<div class="line"><span class="lineno"> 102</span> </div>
<div class="line"><span class="lineno"> 103</span> evaluate(op1, op2, scan, <a class="code hl_class" href="../../d1/dc2/classstack.html">stack</a>);</div>
<div class="line"><span class="lineno"> 104</span> }</div>
<div class="line"><span class="lineno"> 105</span> j++;</div>
<div class="line"><span class="lineno"> 106</span> }</div>
<div class="line"><span class="lineno"> 107</span> </div>
<div class="line"><span class="lineno"> 108</span> std::cout &lt;&lt; <a class="code hl_variable" href="../../dc/dc5/paranthesis__matching_8cpp.html#aa37d24a036d239b3b528f13b9de880c7">stack</a>.<a class="code hl_function" href="../../d1/dc2/classstack.html#ae09630c4384903d187801921b2ddc709">top</a>() &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 109</span> </div>
<div class="line"><span class="lineno"> 110</span> <span class="keywordflow">return</span> <a class="code hl_variable" href="../../dc/dc5/paranthesis__matching_8cpp.html#aa37d24a036d239b3b528f13b9de880c7">stack</a>.top();</div>
<div class="line"><span class="lineno"> 111</span>}</div>
<div class="ttc" id="aclassstack_html_a3647fb4418890f19e0dc414b8092b8b0"><div class="ttname"><a href="../../d1/dc2/classstack.html#a3647fb4418890f19e0dc414b8092b8b0">stack::pop</a></div><div class="ttdeci">void pop()</div><div class="ttdef"><b>Definition</b> <a href="../../df/d47/stack_8hpp_source.html#l00062">stack.hpp:62</a></div></div>
<div class="ttc" id="aclassstack_html_ae09630c4384903d187801921b2ddc709"><div class="ttname"><a href="../../d1/dc2/classstack.html#ae09630c4384903d187801921b2ddc709">stack::top</a></div><div class="ttdeci">value_type top() const</div><div class="ttdef"><b>Definition</b> <a href="../../df/d47/stack_8hpp_source.html#l00056">stack.hpp:56</a></div></div>
<div class="ttc" id="aparanthesis__matching_8cpp_html_aa37d24a036d239b3b528f13b9de880c7"><div class="ttname"><a href="../../dc/dc5/paranthesis__matching_8cpp.html#aa37d24a036d239b3b528f13b9de880c7">stack</a></div><div class="ttdeci">char stack[MAX]</div><div class="ttdef"><b>Definition</b> <a href="../../dc/dc5/paranthesis__matching_8cpp_source.html#l00020">paranthesis_matching.cpp:20</a></div></div>
<div class="ttc" id="apostfix__evaluation_8cpp_html_a4c27f949c9d6659be9f5bd2ccbe1360a"><div class="ttname"><a href="#a4c27f949c9d6659be9f5bd2ccbe1360a">others::postfix_expression::is_number</a></div><div class="ttdeci">bool is_number(const std::string &amp;s)</div><div class="ttdoc">Checks if scanned string is a number.</div><div class="ttdef"><b>Definition</b> <a href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00037">postfix_evaluation.cpp:37</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a6a8eeb7d346d5cd6335d9780fb7c0f15" name="a6a8eeb7d346d5cd6335d9780fb7c0f15"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6a8eeb7d346d5cd6335d9780fb7c0f15">&#9670;&#160;</a></span>test_function_1()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void test_function_1 </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Test function 1 with input array {'2', '3', '1', '*', '+', '9', '-'}. </p>
<dl class="section return"><dt>Returns</dt><dd>none </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00120">120</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 120</span> {</div>
<div class="line"><span class="lineno"> 121</span> std::array&lt;std::string, 7&gt; input = {<span class="stringliteral">&quot;2&quot;</span>, <span class="stringliteral">&quot;3&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;*&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;9&quot;</span>, <span class="stringliteral">&quot;-&quot;</span>};</div>
<div class="line"><span class="lineno"> 122</span> </div>
<div class="line"><span class="lineno"> 123</span> <span class="keywordtype">float</span> answer = <a class="code hl_function" href="#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a>(input);</div>
<div class="line"><span class="lineno"> 124</span> </div>
<div class="line"><span class="lineno"> 125</span> assert(answer == -4);</div>
<div class="line"><span class="lineno"> 126</span>}</div>
<div class="ttc" id="apostfix__evaluation_8cpp_html_ae38bd3a177a6d61da3859a281233bbe1"><div class="ttname"><a href="#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a></div><div class="ttdeci">float postfix_evaluation(std::array&lt; std::string, N &gt; input)</div><div class="ttdoc">Postfix Evaluation algorithm to compute the value from given input array.</div><div class="ttdef"><b>Definition</b> <a href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00088">postfix_evaluation.cpp:88</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a5b97d12e8b61484f756a8721992bfae1" name="a5b97d12e8b61484f756a8721992bfae1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5b97d12e8b61484f756a8721992bfae1">&#9670;&#160;</a></span>test_function_2()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void test_function_2 </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Test function 2 with input array {'100', '200', '+', '2', '/', '5', '*', '7', '+'}. </p>
<dl class="section return"><dt>Returns</dt><dd>none </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00133">133</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 133</span> {</div>
<div class="line"><span class="lineno"> 134</span> std::array&lt;std::string, 9&gt; input = {<span class="stringliteral">&quot;100&quot;</span>, <span class="stringliteral">&quot;200&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;2&quot;</span>, <span class="stringliteral">&quot;/&quot;</span>,</div>
<div class="line"><span class="lineno"> 135</span> <span class="stringliteral">&quot;5&quot;</span>, <span class="stringliteral">&quot;*&quot;</span>, <span class="stringliteral">&quot;7&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>};</div>
<div class="line"><span class="lineno"> 136</span> <span class="keywordtype">float</span> answer = <a class="code hl_function" href="#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a>(input);</div>
<div class="line"><span class="lineno"> 137</span> </div>
<div class="line"><span class="lineno"> 138</span> assert(answer == 757);</div>
<div class="line"><span class="lineno"> 139</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a29c6172e7ccef1d93c1d116f407928dc" name="a29c6172e7ccef1d93c1d116f407928dc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a29c6172e7ccef1d93c1d116f407928dc">&#9670;&#160;</a></span>test_function_3()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void test_function_3 </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p class="definition">Definition at line <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html#l00141">141</a> of file <a class="el" href="../../d7/d75/postfix__evaluation_8cpp_source.html">postfix_evaluation.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 141</span> {</div>
<div class="line"><span class="lineno"> 142</span> std::array&lt;std::string, 43&gt; input = {</div>
<div class="line"><span class="lineno"> 143</span> <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>,</div>
<div class="line"><span class="lineno"> 144</span> <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>,</div>
<div class="line"><span class="lineno"> 145</span> <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>,</div>
<div class="line"><span class="lineno"> 146</span> <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>, <span class="stringliteral">&quot;+&quot;</span>};</div>
<div class="line"><span class="lineno"> 147</span> <span class="keywordtype">float</span> answer = <a class="code hl_function" href="#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a>(input);</div>
<div class="line"><span class="lineno"> 148</span> </div>
<div class="line"><span class="lineno"> 149</span> assert(answer == 22);</div>
<div class="line"><span class="lineno"> 150</span>}</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<div id="page-nav" class="page-nav-panel">
<div id="page-nav-resize-handle"></div>
<div id="page-nav-tree">
<div id="page-nav-contents">
</div><!-- page-nav-contents -->
</div><!-- page-nav-tree -->
</div><!-- page-nav -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a href="../../dir_9510827d0b234b3cc54b29892f217477.html">others</a></li><li class="navelem"><a href="../../d7/d75/postfix__evaluation_8cpp.html">postfix_evaluation.cpp</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.14.0 </li>
</ul>
</div>
</body>
</html>