mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-21 12:23:13 +08:00
395 lines
34 KiB
HTML
395 lines
34 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.12.0"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C++: data_structures/reverse_a_linked_list.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>
|
|
<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="../../resize.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/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"> 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.12.0 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() { codefold.init(1); });
|
|
/* @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&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search',true);
|
|
$(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&dn=expat.txt MIT */
|
|
$(function(){initNavTree('d6/d05/reverse__a__linked__list_8cpp.html','../../'); initResizable(true); });
|
|
/* @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> |
|
|
<a href="#namespaces">Namespaces</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">reverse_a_linked_list.cpp File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>Implementation of <a href="https://simple.wikipedia.org/wiki/Linked_list" target="_blank">Reversing a single linked list</a>
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <cassert></code><br />
|
|
<code>#include <iostream></code><br />
|
|
<code>#include <new></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for reverse_a_linked_list.cpp:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/da2/reverse__a__linked__list_8cpp__incl.svg" width="240" 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">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d0e/classdata__structures_1_1linked__list_1_1_node.html">data_structures::linked_list::Node</a></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
|
|
Namespaces</h2></td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace  </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"> </td><td class="mdescRight">for IO operations <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/db0/namespacelinked__list.html">linked_list</a></td></tr>
|
|
<tr class="memdesc:d3/db0/namespacelinked__list"><td class="mdescLeft"> </td><td class="mdescRight">Functions for singly linked list algorithm. <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:a7f80d9712cc7d77399dcacb4c2917511" id="r_a7f80d9712cc7d77399dcacb4c2917511"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d4/d0e/classdata__structures_1_1linked__list_1_1_node.html">Node</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="#a7f80d9712cc7d77399dcacb4c2917511">data_structures::linked_list::copy_all_nodes</a> (const <a class="el" href="../../d4/d0e/classdata__structures_1_1linked__list_1_1_node.html">Node</a> *const <a class="el" href="../../d5/da1/structnode.html">node</a>)</td></tr>
|
|
<tr class="memdesc:a7f80d9712cc7d77399dcacb4c2917511"><td class="mdescLeft"> </td><td class="mdescRight">creates a deep copy of a list starting at the input node <br /></td></tr>
|
|
<tr class="separator:a7f80d9712cc7d77399dcacb4c2917511"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d" id="r_aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
|
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <br /></td></tr>
|
|
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa4e119e5a427e2b4e0b9ec6297579709" id="r_aa4e119e5a427e2b4e0b9ec6297579709"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#aa4e119e5a427e2b4e0b9ec6297579709">test_copy_constructor</a> ()</td></tr>
|
|
<tr class="separator:aa4e119e5a427e2b4e0b9ec6297579709"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a29e92f516e1606aa6743fc992aab35be" id="r_a29e92f516e1606aa6743fc992aab35be"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#a29e92f516e1606aa6743fc992aab35be">test_assignment_operator</a> ()</td></tr>
|
|
<tr class="separator:a29e92f516e1606aa6743fc992aab35be"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4" id="r_ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p>Implementation of <a href="https://simple.wikipedia.org/wiki/Linked_list" target="_blank">Reversing a single linked list</a> </p>
|
|
<p>The linked list is a data structure used for holding a sequence of values, which can be added, displayed, reversed, or removed. </p>
|
|
<h3><a class="anchor" id="autotoc_md44"></a>
|
|
Algorithm</h3>
|
|
<p>Values can be added by iterating to the end of a list (by following the pointers) starting from the first link. Whichever link points to null is considered the last link and is pointed to the new value.</p>
|
|
<p>Linked List can be reversed by using 3 pointers: current, previous, and next_node; we keep iterating until the last node. Meanwhile, before changing to the next of current, we store it in the next_node pointer, now we store the prev pointer in the current of next, this is where the actual reversal happens. And then we move the prev and current pointers one step forward. Then the head node is made to point to the last node (prev pointer) after completion of an iteration.</p>
|
|
<p><a href="https://drive.google.com/file/d/1pM5COF0wx-wermnNy_svtyZquaCUP2xS/view?usp=sharing" target="_blank">A graphic explanation and view of what's happening behind the scenes</a> </p>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a7f80d9712cc7d77399dcacb4c2917511" name="a7f80d9712cc7d77399dcacb4c2917511"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a7f80d9712cc7d77399dcacb4c2917511">◆ </a></span>copy_all_nodes()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="../../db/d8b/struct_node.html">Node</a> * data_structures::linked_list::copy_all_nodes </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const <a class="el" href="../../d4/d0e/classdata__structures_1_1linked__list_1_1_node.html">Node</a> *const</td> <td class="paramname"><span class="paramname"><em>node</em></span></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>creates a deep copy of a list starting at the input node </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramdir">[in]</td><td class="paramname">node</td><td>pointer to the first node/head of the list to be copied </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>pointer to the first node/head of the copied list or nullptr </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 53</span> {</div>
|
|
<div class="line"><span class="lineno"> 54</span> <span class="keywordflow">if</span> (<a class="code hl_class" href="../../d5/da1/structnode.html">node</a>) {</div>
|
|
<div class="line"><span class="lineno"> 55</span> <span class="comment">// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)</span></div>
|
|
<div class="line"><span class="lineno"> 56</span> <a class="code hl_class" href="../../db/d8b/struct_node.html">Node</a>* res = <span class="keyword">new</span> <a class="code hl_class" href="../../db/d8b/struct_node.html">Node</a>();</div>
|
|
<div class="line"><span class="lineno"> 57</span> res->val = <a class="code hl_class" href="../../d5/da1/structnode.html">node</a>->val;</div>
|
|
<div class="line"><span class="lineno"> 58</span> res->next = <a class="code hl_function" href="#a7f80d9712cc7d77399dcacb4c2917511">copy_all_nodes</a>(<a class="code hl_class" href="../../d5/da1/structnode.html">node</a>->next);</div>
|
|
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">return</span> res;</div>
|
|
<div class="line"><span class="lineno"> 60</span> }</div>
|
|
<div class="line"><span class="lineno"> 61</span> <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
|
|
<div class="line"><span class="lineno"> 62</span>}</div>
|
|
<div class="ttc" id="areverse__a__linked__list_8cpp_html_a7f80d9712cc7d77399dcacb4c2917511"><div class="ttname"><a href="#a7f80d9712cc7d77399dcacb4c2917511">data_structures::linked_list::copy_all_nodes</a></div><div class="ttdeci">Node * copy_all_nodes(const Node *const node)</div><div class="ttdoc">creates a deep copy of a list starting at the input node</div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:53</div></div>
|
|
<div class="ttc" id="astruct_node_html"><div class="ttname"><a href="../../db/d8b/struct_node.html">Node</a></div><div class="ttdef"><b>Definition</b> linkedlist_implentation_usingarray.cpp:14</div></div>
|
|
<div class="ttc" id="astructnode_html"><div class="ttname"><a href="../../d5/da1/structnode.html">node</a></div><div class="ttdef"><b>Definition</b> binary_search_tree.cpp:11</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="../../d6/d05/reverse__a__linked__list_8cpp_a7f80d9712cc7d77399dcacb4c2917511_cgraph.svg" width="164" height="76"><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">◆ </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>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 301</span> {</div>
|
|
<div class="line"><span class="lineno"> 302</span> <a class="code hl_function" href="#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
|
<div class="line"><span class="lineno"> 303</span> test_copy_constructor();</div>
|
|
<div class="line"><span class="lineno"> 304</span> test_assignment_operator();</div>
|
|
<div class="line"><span class="lineno"> 305</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><span class="lineno"> 306</span>}</div>
|
|
<div class="ttc" id="areverse__a__linked__list_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:228</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="../../d6/d05/reverse__a__linked__list_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="555" height="298"><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">◆ </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"><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</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>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 228</span> {</div>
|
|
<div class="line"><span class="lineno"> 229</span> <a class="code hl_class" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a> L;</div>
|
|
<div class="line"><span class="lineno"> 230</span> <span class="comment">// 1st test</span></div>
|
|
<div class="line"><span class="lineno"> 231</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(11);</div>
|
|
<div class="line"><span class="lineno"> 232</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(12);</div>
|
|
<div class="line"><span class="lineno"> 233</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(15);</div>
|
|
<div class="line"><span class="lineno"> 234</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(10);</div>
|
|
<div class="line"><span class="lineno"> 235</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(-12);</div>
|
|
<div class="line"><span class="lineno"> 236</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(-20);</div>
|
|
<div class="line"><span class="lineno"> 237</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(18);</div>
|
|
<div class="line"><span class="lineno"> 238</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a9785d1478e59f5a90288b2928a7094d6">top</a>() == 11);</div>
|
|
<div class="line"><span class="lineno"> 239</span> assert(L.<a class="code hl_variable" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#af39bcc08641ce0c813023f364a9a9015">last</a>() == 18);</div>
|
|
<div class="line"><span class="lineno"> 240</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#ac466ec086c0835822467bd3d8f3ab90e">reverseList</a>();</div>
|
|
<div class="line"><span class="lineno"> 241</span> <span class="comment">// Reversal Testing</span></div>
|
|
<div class="line"><span class="lineno"> 242</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a9785d1478e59f5a90288b2928a7094d6">top</a>() == 18);</div>
|
|
<div class="line"><span class="lineno"> 243</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(1) == -20);</div>
|
|
<div class="line"><span class="lineno"> 244</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(2) == -12);</div>
|
|
<div class="line"><span class="lineno"> 245</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(3) == 10);</div>
|
|
<div class="line"><span class="lineno"> 246</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(4) == 15);</div>
|
|
<div class="line"><span class="lineno"> 247</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(5) == 12);</div>
|
|
<div class="line"><span class="lineno"> 248</span> assert(L.<a class="code hl_variable" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#af39bcc08641ce0c813023f364a9a9015">last</a>() == 11);</div>
|
|
<div class="line"><span class="lineno"> 249</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"All tests have successfully passed!"</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
|
<div class="line"><span class="lineno"> 250</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="aclassdata__structures_1_1linked__list_1_1list_html"><div class="ttname"><a href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a></div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:68</div></div>
|
|
<div class="ttc" id="aclassdata__structures_1_1linked__list_1_1list_html_a2b951a3f1123b9b2f4891ec96aa76d69"><div class="ttname"><a href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">data_structures::linked_list::list::traverse</a></div><div class="ttdeci">int32_t traverse(int32_t index) const</div><div class="ttdoc">Utility function to find the i th element of the list.</div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:168</div></div>
|
|
<div class="ttc" id="aclassdata__structures_1_1linked__list_1_1list_html_a9785d1478e59f5a90288b2928a7094d6"><div class="ttname"><a href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a9785d1478e59f5a90288b2928a7094d6">data_structures::linked_list::list::top</a></div><div class="ttdeci">int32_t top() const</div><div class="ttdoc">Utility function to find the top element of the list.</div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:142</div></div>
|
|
<div class="ttc" id="aclassdata__structures_1_1linked__list_1_1list_html_aa69707af46eb6d410eb3a54ee58e1ed1"><div class="ttname"><a href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">data_structures::linked_list::list::insert</a></div><div class="ttdeci">void insert(int32_t new_elem)</div><div class="ttdoc">Utility function that adds a new element at the end of the list.</div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:99</div></div>
|
|
<div class="ttc" id="aclassdata__structures_1_1linked__list_1_1list_html_ac466ec086c0835822467bd3d8f3ab90e"><div class="ttname"><a href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#ac466ec086c0835822467bd3d8f3ab90e">data_structures::linked_list::list::reverseList</a></div><div class="ttdeci">void reverseList()</div><div class="ttdoc">Utility function for reversing a list.</div><div class="ttdef"><b>Definition</b> reverse_a_linked_list.cpp:125</div></div>
|
|
<div class="ttc" id="aclassdata__structures_1_1linked__list_1_1list_html_af39bcc08641ce0c813023f364a9a9015"><div class="ttname"><a href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#af39bcc08641ce0c813023f364a9a9015">data_structures::linked_list::list::last</a></div><div class="ttdeci">std::shared_ptr< link > last</div><div class="ttdoc">last link on the list</div><div class="ttdef"><b>Definition</b> linked_list.cpp:84</div></div>
|
|
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</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="../../d6/d05/reverse__a__linked__list_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="458" height="298"><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="a29e92f516e1606aa6743fc992aab35be" name="a29e92f516e1606aa6743fc992aab35be"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a29e92f516e1606aa6743fc992aab35be">◆ </a></span>test_assignment_operator()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_assignment_operator </td>
|
|
<td>(</td>
|
|
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<div class="fragment"><div class="line"><span class="lineno"> 274</span> {</div>
|
|
<div class="line"><span class="lineno"> 275</span> <a class="code hl_class" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a> L;</div>
|
|
<div class="line"><span class="lineno"> 276</span> <a class="code hl_class" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a> otherList;</div>
|
|
<div class="line"><span class="lineno"> 277</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(10);</div>
|
|
<div class="line"><span class="lineno"> 278</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(20);</div>
|
|
<div class="line"><span class="lineno"> 279</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(30);</div>
|
|
<div class="line"><span class="lineno"> 280</span> otherList = L;</div>
|
|
<div class="line"><span class="lineno"> 281</span> </div>
|
|
<div class="line"><span class="lineno"> 282</span> otherList.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(40);</div>
|
|
<div class="line"><span class="lineno"> 283</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(400);</div>
|
|
<div class="line"><span class="lineno"> 284</span> </div>
|
|
<div class="line"><span class="lineno"> 285</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a9785d1478e59f5a90288b2928a7094d6">top</a>() == 10);</div>
|
|
<div class="line"><span class="lineno"> 286</span> assert(otherList.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a9785d1478e59f5a90288b2928a7094d6">top</a>() == 10);</div>
|
|
<div class="line"><span class="lineno"> 287</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(1) == 20);</div>
|
|
<div class="line"><span class="lineno"> 288</span> assert(otherList.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(1) == 20);</div>
|
|
<div class="line"><span class="lineno"> 289</span> </div>
|
|
<div class="line"><span class="lineno"> 290</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(2) == 30);</div>
|
|
<div class="line"><span class="lineno"> 291</span> assert(otherList.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(2) == 30);</div>
|
|
<div class="line"><span class="lineno"> 292</span> </div>
|
|
<div class="line"><span class="lineno"> 293</span> assert(L.<a class="code hl_variable" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#af39bcc08641ce0c813023f364a9a9015">last</a>() == 400);</div>
|
|
<div class="line"><span class="lineno"> 294</span> assert(otherList.<a class="code hl_variable" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#af39bcc08641ce0c813023f364a9a9015">last</a>() == 40);</div>
|
|
<div class="line"><span class="lineno"> 295</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="aa4e119e5a427e2b4e0b9ec6297579709" name="aa4e119e5a427e2b4e0b9ec6297579709"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa4e119e5a427e2b4e0b9ec6297579709">◆ </a></span>test_copy_constructor()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_copy_constructor </td>
|
|
<td>(</td>
|
|
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
<div class="fragment"><div class="line"><span class="lineno"> 252</span> {</div>
|
|
<div class="line"><span class="lineno"> 253</span> <a class="code hl_class" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a> L;</div>
|
|
<div class="line"><span class="lineno"> 254</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(10);</div>
|
|
<div class="line"><span class="lineno"> 255</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(20);</div>
|
|
<div class="line"><span class="lineno"> 256</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(30);</div>
|
|
<div class="line"><span class="lineno"> 257</span> <a class="code hl_class" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html">data_structures::linked_list::list</a> otherList(L);</div>
|
|
<div class="line"><span class="lineno"> 258</span> otherList.insert(40);</div>
|
|
<div class="line"><span class="lineno"> 259</span> </div>
|
|
<div class="line"><span class="lineno"> 260</span> L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#aa69707af46eb6d410eb3a54ee58e1ed1">insert</a>(400);</div>
|
|
<div class="line"><span class="lineno"> 261</span> </div>
|
|
<div class="line"><span class="lineno"> 262</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a9785d1478e59f5a90288b2928a7094d6">top</a>() == 10);</div>
|
|
<div class="line"><span class="lineno"> 263</span> assert(otherList.top() == 10);</div>
|
|
<div class="line"><span class="lineno"> 264</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(1) == 20);</div>
|
|
<div class="line"><span class="lineno"> 265</span> assert(otherList.traverse(1) == 20);</div>
|
|
<div class="line"><span class="lineno"> 266</span> </div>
|
|
<div class="line"><span class="lineno"> 267</span> assert(L.<a class="code hl_function" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#a2b951a3f1123b9b2f4891ec96aa76d69">traverse</a>(2) == 30);</div>
|
|
<div class="line"><span class="lineno"> 268</span> assert(otherList.traverse(2) == 30);</div>
|
|
<div class="line"><span class="lineno"> 269</span> </div>
|
|
<div class="line"><span class="lineno"> 270</span> assert(L.<a class="code hl_variable" href="../../d1/def/classdata__structures_1_1linked__list_1_1list.html#af39bcc08641ce0c813023f364a9a9015">last</a>() == 400);</div>
|
|
<div class="line"><span class="lineno"> 271</span> assert(otherList.last() == 40);</div>
|
|
<div class="line"><span class="lineno"> 272</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="../../dir_2e746e9d06bf2d8ff842208bcc6ebcfc.html">data_structures</a></li><li class="navelem"><a class="el" href="../../d6/d05/reverse__a__linked__list_8cpp.html">reverse_a_linked_list.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.12.0 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|