Files
C-Plus-Plus/d7/d00/list__array_8cpp.html
2023-06-16 21:23:15 +00:00

270 lines
20 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" 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.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: data_structures/list_array.cpp 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 id="projectrow">
<td id="projectalign">
<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.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../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('d7/d00/list__array_8cpp.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">
<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="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">list_array.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p><a href="https://en.wikipedia.org/wiki/Dynamic_array" target="_blank">Dynamic Array</a>
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;iostream&gt;</code><br />
<code>#include &lt;array&gt;</code><br />
<code>#include &lt;cassert&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for list_array.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dd/d4d/list__array_8cpp__incl.svg" width="246" height="126"><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>
Classes</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="../../d5/dab/structdata__structures_1_1list__array_1_1list.html">data_structures::list_array::list&lt; N &gt;</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">Structure of List with supporting methods. <a href="../../d5/dab/structdata__structures_1_1list__array_1_1list.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="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:d5/d3c/namespacedata__structures"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d3c/namespacedata__structures.html">data_structures</a></td></tr>
<tr class="memdesc:d5/d3c/namespacedata__structures"><td class="mdescLeft">&#160;</td><td class="mdescRight">for IO operations <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:d9/d27/namespacelist__array"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/d27/namespacelist__array.html">list_array</a></td></tr>
<tr class="memdesc:d9/d27/namespacelist__array"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for <a href="https://en.wikipedia.org/wiki/Dynamic_array" target="_blank">Dynamic Array</a> algorithm. <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:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d00/list__array_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Test implementations. <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="../../d7/d00/list__array_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><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://en.wikipedia.org/wiki/Dynamic_array" target="_blank">Dynamic Array</a> </p>
<p>The <a class="el" href="../../d9/d27/namespacelist__array.html" title="Functions for Dynamic Array algorithm.">list_array</a> is the implementation of list represented using array. We can perform basic CRUD operations as well as other operations like sorting etc.</p>
<h3><a class="anchor" id="autotoc_md42"></a>
Algorithm</h3>
<p>It implements various method like insert, sort, search etc. efficiently. You can select the operation and methods will do the rest work for you. You can insert element, sort them in order, search efficiently, delete values and print the list. </p>
</div><h2 class="groupheader">Function Documentation</h2>
<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&#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>
<div class="fragment"><div class="line"><span class="lineno"> 248</span> {</div>
<div class="line"><span class="lineno"> 249</span> <a class="code hl_function" href="../../d7/d00/list__array_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// Execute the tests</span></div>
<div class="line"><span class="lineno"> 250</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 251</span>}</div>
<div class="ttc" id="alist__array_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d7/d00/list__array_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Test implementations.</div><div class="ttdef"><b>Definition:</b> list_array.cpp:206</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="../../d7/d00/list__array_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="463" height="248"><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="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">&#9670;&#160;</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="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>Test implementations. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 206</span> {</div>
<div class="line"><span class="lineno"> 207</span> <a class="code hl_struct" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html">data_structures::list_array::list&lt;50&gt;</a> L;</div>
<div class="line"><span class="lineno"> 208</span> </div>
<div class="line"><span class="lineno"> 209</span> <span class="comment">// Insert testing</span></div>
<div class="line"><span class="lineno"> 210</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(11);</div>
<div class="line"><span class="lineno"> 211</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(12);</div>
<div class="line"><span class="lineno"> 212</span> assert(L.top == 2);</div>
<div class="line"><span class="lineno"> 213</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(15);</div>
<div class="line"><span class="lineno"> 214</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(10);</div>
<div class="line"><span class="lineno"> 215</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(12);</div>
<div class="line"><span class="lineno"> 216</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(20);</div>
<div class="line"><span class="lineno"> 217</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">insert</a>(18);</div>
<div class="line"><span class="lineno"> 218</span> assert(L.top == 7);</div>
<div class="line"><span class="lineno"> 219</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a0b7acf65026df1e9dd13eebf309dda5e">show</a>(); <span class="comment">// To print the array</span></div>
<div class="line"><span class="lineno"> 220</span> </div>
<div class="line"><span class="lineno"> 221</span> <span class="comment">// Remove testing</span></div>
<div class="line"><span class="lineno"> 222</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a98f7d9079c0868e0f4e67d5c52174fb6">remove</a>(12); <span class="comment">// Remove Duplicate value in the list</span></div>
<div class="line"><span class="lineno"> 223</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a98f7d9079c0868e0f4e67d5c52174fb6">remove</a>(15); <span class="comment">// Remove the existing value in the list</span></div>
<div class="line"><span class="lineno"> 224</span> assert(L.top == 5);</div>
<div class="line"><span class="lineno"> 225</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a98f7d9079c0868e0f4e67d5c52174fb6">remove</a>(50); <span class="comment">// Try to remove the non-existing value in the list</span></div>
<div class="line"><span class="lineno"> 226</span> assert(L.top == 5);</div>
<div class="line"><span class="lineno"> 227</span> </div>
<div class="line"><span class="lineno"> 228</span> <span class="comment">// LinearSearch testing</span></div>
<div class="line"><span class="lineno"> 229</span> assert(L.search(11) == 0); <span class="comment">// search for the existing element</span></div>
<div class="line"><span class="lineno"> 230</span> assert(L.search(12) == 2);</div>
<div class="line"><span class="lineno"> 231</span> assert(L.search(50) == -1); <span class="comment">// search for the non-existing element</span></div>
<div class="line"><span class="lineno"> 232</span> </div>
<div class="line"><span class="lineno"> 233</span> <span class="comment">// Sort testing</span></div>
<div class="line"><span class="lineno"> 234</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a133635ad53bd89e3947ca02448819180">sort</a>();</div>
<div class="line"><span class="lineno"> 235</span> assert(L.isSorted == <span class="keyword">true</span>);</div>
<div class="line"><span class="lineno"> 236</span> L.<a class="code hl_function" href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a0b7acf65026df1e9dd13eebf309dda5e">show</a>();</div>
<div class="line"><span class="lineno"> 237</span> </div>
<div class="line"><span class="lineno"> 238</span> <span class="comment">// BinarySearch testing</span></div>
<div class="line"><span class="lineno"> 239</span> assert(L.search(11) == 1); <span class="comment">// search for the existing element</span></div>
<div class="line"><span class="lineno"> 240</span> assert(L.search(12) == 2);</div>
<div class="line"><span class="lineno"> 241</span> assert(L.search(50) == -1); <span class="comment">// search for the non-existing element</span></div>
<div class="line"><span class="lineno"> 242</span>}</div>
<div class="ttc" id="astructdata__structures_1_1list__array_1_1list_html"><div class="ttname"><a href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html">data_structures::list_array::list</a></div><div class="ttdoc">Structure of List with supporting methods.</div><div class="ttdef"><b>Definition:</b> list_array.cpp:33</div></div>
<div class="ttc" id="astructdata__structures_1_1list__array_1_1list_html_a0b7acf65026df1e9dd13eebf309dda5e"><div class="ttname"><a href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a0b7acf65026df1e9dd13eebf309dda5e">data_structures::list_array::list::show</a></div><div class="ttdeci">void show()</div><div class="ttdoc">Utility function to print array.</div><div class="ttdef"><b>Definition:</b> list_array.cpp:191</div></div>
<div class="ttc" id="astructdata__structures_1_1list__array_1_1list_html_a133635ad53bd89e3947ca02448819180"><div class="ttname"><a href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a133635ad53bd89e3947ca02448819180">data_structures::list_array::list::sort</a></div><div class="ttdeci">void sort()</div><div class="ttdoc">Sort the list.</div><div class="ttdef"><b>Definition:</b> list_array.cpp:111</div></div>
<div class="ttc" id="astructdata__structures_1_1list__array_1_1list_html_a98f7d9079c0868e0f4e67d5c52174fb6"><div class="ttname"><a href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#a98f7d9079c0868e0f4e67d5c52174fb6">data_structures::list_array::list::remove</a></div><div class="ttdeci">void remove(const uint64_t &amp;val)</div><div class="ttdoc">To remove the element from the list.</div><div class="ttdef"><b>Definition:</b> list_array.cpp:172</div></div>
<div class="ttc" id="astructdata__structures_1_1list__array_1_1list_html_aa960d714d449612f25256850d72325f1"><div class="ttname"><a href="../../d5/dab/structdata__structures_1_1list__array_1_1list.html#aa960d714d449612f25256850d72325f1">data_structures::list_array::list::insert</a></div><div class="ttdeci">void insert(const uint64_t &amp;val)</div><div class="ttdoc">Insert the new element in the list.</div><div class="ttdef"><b>Definition:</b> list_array.cpp:133</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="../../d7/d00/list__array_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="366" height="248"><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_2e746e9d06bf2d8ff842208bcc6ebcfc.html">data_structures</a></li><li class="navelem"><a class="el" href="../../d7/d00/list__array_8cpp.html">list_array.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.9.6 </li>
</ul>
</div>
</body>
</html>