mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-11-30 16:06:24 +08:00
Documentation for f4403718ef
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<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.8.20"/>
|
||||
<meta name="generator" content="Doxygen 1.9.1"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: others/postfix_evaluation.cpp File Reference</title>
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
@@ -42,10 +42,10 @@
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.8.20 -->
|
||||
<!-- 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');
|
||||
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.html');
|
||||
/* @license-end */
|
||||
</script>
|
||||
<script type="text/javascript" src="../../menudata.js"></script>
|
||||
@@ -158,7 +158,8 @@ Functions</h2></td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Evaluation of <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">Postfix Expression</a> </p>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/Darshana-Sarma">Darshana Sarma</a> 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 </dd></dl>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/Darshana-Sarma">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>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a59fd597e0ea394abe027ced4d2ea3338"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a59fd597e0ea394abe027ced4d2ea3338">◆ </a></span>evaluate()</h2>
|
||||
@@ -238,6 +239,10 @@ Functions</h2></td></tr>
|
||||
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">break</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 class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="ac_str_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/c_str.html">std::string::c_str</a></div><div class="ttdeci">T c_str(T... args)</div></div>
|
||||
<div class="ttc" id="aclassstack_html"><div class="ttname"><a href="../../d1/dc2/classstack.html">stack</a></div><div class="ttdef"><b>Definition:</b> stack.h:26</div></div>
|
||||
<div class="ttc" id="aparanthesis__matching_8cpp_html_aae41c72130114bf31204cde6873b6095"><div class="ttname"><a href="../../dc/dc5/paranthesis__matching_8cpp.html#aae41c72130114bf31204cde6873b6095">push</a></div><div class="ttdeci">void push(char ch)</div><div class="ttdoc">push byte to stack variable</div><div class="ttdef"><b>Definition:</b> paranthesis_matching.cpp:26</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@@ -274,6 +279,10 @@ Here is the call graph for this function:</div>
|
||||
<div class="fragment"><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  {</div>
|
||||
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <span class="keywordflow">return</span> !s.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/empty.html">empty</a>() && <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/all_any_none_of.html">std::all_of</a>(s.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/begin.html">begin</a>(), s.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/end.html">end</a>(), ::isdigit);</div>
|
||||
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span> }</div>
|
||||
<div class="ttc" id="aall_any_none_of_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/all_any_none_of.html">std::all_of</a></div><div class="ttdeci">T all_of(T... args)</div></div>
|
||||
<div class="ttc" id="abegin_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/begin.html">std::string::begin</a></div><div class="ttdeci">T begin(T... args)</div></div>
|
||||
<div class="ttc" id="aempty_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/empty.html">std::string::empty</a></div><div class="ttdeci">T empty(T... args)</div></div>
|
||||
<div class="ttc" id="aend_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/end.html">std::string::end</a></div><div class="ttdeci">T end(T... args)</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@@ -309,6 +318,8 @@ Here is the call graph for this function:</div>
|
||||
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  </div>
|
||||
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span> }</div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a5b97d12e8b61484f756a8721992bfae1"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a5b97d12e8b61484f756a8721992bfae1">test_function_2</a></div><div class="ttdeci">static void test_function_2()</div><div class="ttdoc">Test function 2 with input array {'1', '2', '+', '2', '/', '5', '*', '7', '+'}.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:159</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a6a8eeb7d346d5cd6335d9780fb7c0f15"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a6a8eeb7d346d5cd6335d9780fb7c0f15">test_function_1</a></div><div class="ttdeci">static void test_function_1()</div><div class="ttdoc">Test function 1 with input array {'2', '3', '1', '*', '+', '9', '-'}.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:146</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@@ -347,6 +358,8 @@ Here is the call graph for this function:</div>
|
||||
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <a class="code" href="../../d1/dc2/classstack.html">stack</a>-><a class="code" href="../../d1/dc2/classstack.html#a7289037c059aaad492b4d68e6bd54453">stackTop</a>--;</div>
|
||||
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <span class="keywordflow">return</span> operand;</div>
|
||||
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span> }</div>
|
||||
<div class="ttc" id="aclassstack_html_a5b64337ec34b12e98458bb9b9d5f8f83"><div class="ttname"><a href="../../d1/dc2/classstack.html#a5b64337ec34b12e98458bb9b9d5f8f83">stack::stack</a></div><div class="ttdeci">stack()</div><div class="ttdef"><b>Definition:</b> stack.h:41</div></div>
|
||||
<div class="ttc" id="aclassstack_html_a7289037c059aaad492b4d68e6bd54453"><div class="ttname"><a href="../../d1/dc2/classstack.html#a7289037c059aaad492b4d68e6bd54453">stack::stackTop</a></div><div class="ttdeci">node< Type > * stackTop</div><div class="ttdef"><b>Definition:</b> stack.h:146</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@@ -410,6 +423,12 @@ template<std::size_t N> </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="keywordflow">return</span> <a class="code" href="../../d1/dc2/classstack.html">stack</a>.<a class="code" href="../../d1/dc2/classstack.html#a5b64337ec34b12e98458bb9b9d5f8f83">stack</a>[<a class="code" href="../../d1/dc2/classstack.html">stack</a>.<a class="code" href="../../d1/dc2/classstack.html#a7289037c059aaad492b4d68e6bd54453">stackTop</a>];</div>
|
||||
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span> }</div>
|
||||
<div class="ttc" id="abasic_string_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a></div></div>
|
||||
<div class="ttc" id="aparanthesis__matching_8cpp_html_a6d25c7dfbfeb52c3cb9d1b56ab49b664"><div class="ttname"><a href="../../dc/dc5/paranthesis__matching_8cpp.html#a6d25c7dfbfeb52c3cb9d1b56ab49b664">pop</a></div><div class="ttdeci">char pop()</div><div class="ttdoc">pop a byte out of stack variable</div><div class="ttdef"><b>Definition:</b> paranthesis_matching.cpp:29</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> paranthesis_matching.cpp:20</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a4c27f949c9d6659be9f5bd2ccbe1360a"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a4c27f949c9d6659be9f5bd2ccbe1360a">others::postfix_expression::is_number</a></div><div class="ttdeci">bool is_number(const std::string &s)</div><div class="ttdoc">Checks if scanned string is a number.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:65</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a59fd597e0ea394abe027ced4d2ea3338"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a59fd597e0ea394abe027ced4d2ea3338">others::postfix_expression::evaluate</a></div><div class="ttdeci">void evaluate(float a, float b, const std::string &operation, Stack *stack)</div><div class="ttdoc">Evaluate answer using given last two operands from and operation.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:77</div></div>
|
||||
<div class="ttc" id="astof_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/stof.html">std::stof</a></div><div class="ttdeci">T stof(T... args)</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@@ -499,6 +518,8 @@ Here is the call graph for this function:</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>  assert(answer == -4);</div>
|
||||
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span> }</div>
|
||||
<div class="ttc" id="aarray_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a></div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_ae38bd3a177a6d61da3859a281233bbe1"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a></div><div class="ttdeci">float postfix_evaluation(std::array< std::string, N > input)</div><div class="ttdoc">Postfix Evaluation algorithm to compute the value from given input array.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:115</div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
@@ -539,31 +560,11 @@ Here is the call graph for this function:</div>
|
||||
</div>
|
||||
</div><!-- contents -->
|
||||
</div><!-- doc-content -->
|
||||
<div class="ttc" id="abasic_string_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a></div><div class="ttdoc">STL class.</div></div>
|
||||
<div class="ttc" id="aall_any_none_of_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/all_any_none_of.html">std::all_of</a></div><div class="ttdeci">T all_of(T... args)</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a4c27f949c9d6659be9f5bd2ccbe1360a"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a4c27f949c9d6659be9f5bd2ccbe1360a">others::postfix_expression::is_number</a></div><div class="ttdeci">bool is_number(const std::string &s)</div><div class="ttdoc">Checks if scanned string is a number.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:65</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a5b97d12e8b61484f756a8721992bfae1"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a5b97d12e8b61484f756a8721992bfae1">test_function_2</a></div><div class="ttdeci">static void test_function_2()</div><div class="ttdoc">Test function 2 with input array {'1', '2', '+', '2', '/', '5', '*', '7', '+'}.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:159</div></div>
|
||||
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="ac_str_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/c_str.html">std::string::c_str</a></div><div class="ttdeci">T c_str(T... args)</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_ae38bd3a177a6d61da3859a281233bbe1"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#ae38bd3a177a6d61da3859a281233bbe1">others::postfix_expression::postfix_evaluation</a></div><div class="ttdeci">float postfix_evaluation(std::array< std::string, N > input)</div><div class="ttdoc">Postfix Evaluation algorithm to compute the value from given input array.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:115</div></div>
|
||||
<div class="ttc" id="aarray_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a></div><div class="ttdoc">STL class.</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a6a8eeb7d346d5cd6335d9780fb7c0f15"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a6a8eeb7d346d5cd6335d9780fb7c0f15">test_function_1</a></div><div class="ttdeci">static void test_function_1()</div><div class="ttdoc">Test function 1 with input array {'2', '3', '1', '*', '+', '9', '-'}.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:146</div></div>
|
||||
<div class="ttc" id="apostfix__evaluation_8cpp_html_a59fd597e0ea394abe027ced4d2ea3338"><div class="ttname"><a href="../../d7/d75/postfix__evaluation_8cpp.html#a59fd597e0ea394abe027ced4d2ea3338">others::postfix_expression::evaluate</a></div><div class="ttdeci">void evaluate(float a, float b, const std::string &operation, Stack *stack)</div><div class="ttdoc">Evaluate answer using given last two operands from and operation.</div><div class="ttdef"><b>Definition:</b> postfix_evaluation.cpp:77</div></div>
|
||||
<div class="ttc" id="astof_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/stof.html">std::stof</a></div><div class="ttdeci">T stof(T... args)</div></div>
|
||||
<div class="ttc" id="aclassstack_html_a5b64337ec34b12e98458bb9b9d5f8f83"><div class="ttname"><a href="../../d1/dc2/classstack.html#a5b64337ec34b12e98458bb9b9d5f8f83">stack::stack</a></div><div class="ttdeci">stack()</div><div class="ttdef"><b>Definition:</b> stack.h:41</div></div>
|
||||
<div class="ttc" id="abegin_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/begin.html">std::string::begin</a></div><div class="ttdeci">T begin(T... args)</div></div>
|
||||
<div class="ttc" id="aclassstack_html"><div class="ttname"><a href="../../d1/dc2/classstack.html">stack</a></div><div class="ttdef"><b>Definition:</b> stack.h:26</div></div>
|
||||
<div class="ttc" id="aempty_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/empty.html">std::string::empty</a></div><div class="ttdeci">T empty(T... args)</div></div>
|
||||
<div class="ttc" id="aclassstack_html_a7289037c059aaad492b4d68e6bd54453"><div class="ttname"><a href="../../d1/dc2/classstack.html#a7289037c059aaad492b4d68e6bd54453">stack::stackTop</a></div><div class="ttdeci">node< Type > * stackTop</div><div class="ttdef"><b>Definition:</b> stack.h:146</div></div>
|
||||
<div class="ttc" id="aend_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/end.html">std::string::end</a></div><div class="ttdeci">T end(T... args)</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> paranthesis_matching.cpp:20</div></div>
|
||||
<div class="ttc" id="aparanthesis__matching_8cpp_html_aae41c72130114bf31204cde6873b6095"><div class="ttname"><a href="../../dc/dc5/paranthesis__matching_8cpp.html#aae41c72130114bf31204cde6873b6095">push</a></div><div class="ttdeci">void push(char ch)</div><div class="ttdoc">push byte to stack variable</div><div class="ttdef"><b>Definition:</b> paranthesis_matching.cpp:26</div></div>
|
||||
<div class="ttc" id="aparanthesis__matching_8cpp_html_a6d25c7dfbfeb52c3cb9d1b56ab49b664"><div class="ttname"><a href="../../dc/dc5/paranthesis__matching_8cpp.html#a6d25c7dfbfeb52c3cb9d1b56ab49b664">pop</a></div><div class="ttdeci">char pop()</div><div class="ttdoc">pop a byte out of stack variable</div><div class="ttdef"><b>Definition:</b> paranthesis_matching.cpp:29</div></div>
|
||||
<!-- start footer part -->
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_9510827d0b234b3cc54b29892f217477.html">others</a></li><li class="navelem"><a class="el" href="../../d7/d75/postfix__evaluation_8cpp.html">postfix_evaluation.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="http://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20 </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>
|
||||
|
||||
Reference in New Issue
Block a user