mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-12 11:37:18 +08:00
Documentation for 8b1eab204b
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<!-- 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>
|
||||
@@ -5,10 +6,15 @@
|
||||
<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++: search/median_search2.cpp File Reference</title>
|
||||
<title>TheAlgorithms/C++: search/median_search2.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>
|
||||
@@ -18,14 +24,24 @@
|
||||
<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 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" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></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! -->
|
||||
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
|
||||
<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">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
||||
<div id="projectname">TheAlgorithms/C++<span id="projectnumber"> 1.0.0</span>
|
||||
</div>
|
||||
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
||||
<div id="projectbrief">All the algorithms implemented in C++</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -121,7 +138,9 @@ Include dependency graph for median_search2.cpp:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d9/d73/median__search2_8cpp__incl.svg" width="195" 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><table class="memberdecls">
|
||||
</div>
|
||||
<p><a href="../../d8/dfa/median__search2_8cpp_source.html">Go to the source code of this file.</a></p>
|
||||
<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  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/da4/struct_list_node.html">ListNode</a></td></tr>
|
||||
@@ -158,6 +177,8 @@ hare"](<a href="https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_a
|
||||
<p>Here are some example lists you can use to see how the algorithm works A = [1,2,3,4,5] B = [1,2,3,4,5,6] print median(A) #should be 39 print median(B) #should be 4</p>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/weiss-ben" target="_blank">Benjamin Weiss</a> </dd></dl>
|
||||
<dl class="section see"><dt>See also</dt><dd><a class="el" href="../../d9/d69/median__search_8cpp.html" title="Implementation of Median search algorithm. @cases from here">median_search.cpp</a> </dd></dl>
|
||||
|
||||
<p class="definition">Definition in file <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html">median_search2.cpp</a>.</p>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a565d9d4b66467f966b4e4f8ea2a2ef09" name="a565d9d4b66467f966b4e4f8ea2a2ef09"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a565d9d4b66467f966b4e4f8ea2a2ef09">◆ </a></span>deleteAll()</h2>
|
||||
@@ -173,6 +194,8 @@ hare"](<a href="https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_a
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html#l00077">77</a> of file <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html">median_search2.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 77</span> {</div>
|
||||
<div class="line"><span class="lineno"> 78</span> <span class="keywordflow">if</span> (head) {</div>
|
||||
<div class="line"><span class="lineno"> 79</span> deleteAll(head->next);</div>
|
||||
@@ -199,17 +222,14 @@ hare"](<a href="https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_a
|
||||
|
||||
<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="../../d8/dfa/median__search2_8cpp_source.html#l00139">139</a> of file <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html">median_search2.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 139</span> {</div>
|
||||
<div class="line"><span class="lineno"> 140</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"> 141</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><span class="lineno"> 142</span>}</div>
|
||||
<div class="ttc" id="amedian__search2_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> median_search2.cpp:90</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="../../d8/dfa/median__search2_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="152" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
<div class="ttc" id="amedian__search2_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> <a href="../../d8/dfa/median__search2_8cpp_source.html#l00090">median_search2.cpp:90</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="a5fefe132a0c3ee780ebc703f37ebce6a" name="a5fefe132a0c3ee780ebc703f37ebce6a"></a>
|
||||
@@ -233,6 +253,8 @@ Here is the call graph for this function:</div>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>Median node of the linked list. </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html#l00059">59</a> of file <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html">median_search2.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 59</span> {</div>
|
||||
<div class="line"><span class="lineno"> 60</span> <span class="keywordflow">if</span> (!head) {</div>
|
||||
<div class="line"><span class="lineno"> 61</span> <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
|
||||
@@ -250,14 +272,9 @@ Here is the call graph for this function:</div>
|
||||
<div class="line"><span class="lineno"> 73</span> </div>
|
||||
<div class="line"><span class="lineno"> 74</span> <span class="keywordflow">return</span> (fastptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>) ? slowptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> : slowptr;</div>
|
||||
<div class="line"><span class="lineno"> 75</span>}</div>
|
||||
<div class="ttc" id="astruct_list_node_html"><div class="ttname"><a href="../../d7/da4/struct_list_node.html">ListNode</a></div><div class="ttdoc">for IO operations</div><div class="ttdef"><b>Definition</b> median_search2.cpp:31</div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_ad78b392c2ddc25c3243d0c2f30692fb1"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">ListNode::next</a></div><div class="ttdeci">ListNode * next</div><div class="ttdoc">pointer to the next node</div><div class="ttdef"><b>Definition</b> median_search2.cpp:33</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="../../d8/dfa/median__search2_8cpp_a5fefe132a0c3ee780ebc703f37ebce6a_cgraph.svg" width="175" 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 class="ttc" id="astruct_list_node_html"><div class="ttname"><a href="../../d7/da4/struct_list_node.html">ListNode</a></div><div class="ttdoc">for IO operations</div><div class="ttdef"><b>Definition</b> <a href="../../d8/dfa/median__search2_8cpp_source.html#l00031">median_search2.cpp:31</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_ad78b392c2ddc25c3243d0c2f30692fb1"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">ListNode::next</a></div><div class="ttdeci">ListNode * next</div><div class="ttdoc">pointer to the next node</div><div class="ttdef"><b>Definition</b> <a href="../../d8/dfa/median__search2_8cpp_source.html#l00033">median_search2.cpp:33</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
|
||||
@@ -285,6 +302,8 @@ Here is the call graph for this function:</div>
|
||||
|
||||
<p>Self-test implementations. </p>
|
||||
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html#l00090">90</a> of file <a class="el" href="../../d8/dfa/median__search2_8cpp_source.html">median_search2.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 90</span> {</div>
|
||||
<div class="line"><span class="lineno"> 91</span> <span class="keyword">auto</span>* head1 = <span class="keyword">new</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>;</div>
|
||||
<div class="line"><span class="lineno"> 92</span> head1-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a> = 1;</div>
|
||||
@@ -304,7 +323,7 @@ Here is the call graph for this function:</div>
|
||||
<div class="line"><span class="lineno"> 106</span> <span class="keyword">const</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <span class="keyword">const</span> median = <a class="code hl_function" href="#a5fefe132a0c3ee780ebc703f37ebce6a">search::median_search2::middleNode</a>(head1);</div>
|
||||
<div class="line"><span class="lineno"> 107</span> assert(3 == median-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>); <span class="comment">// 3 is the value of the median node.</span></div>
|
||||
<div class="line"><span class="lineno"> 108</span> search::median_search2::deleteAll(head1);</div>
|
||||
<div class="line"><span class="lineno"> 109</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">"test case:1 passed\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 109</span> std::cout << <span class="stringliteral">"test case:1 passed\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 110</span> </div>
|
||||
<div class="line"><span class="lineno"> 111</span> <span class="comment">// Test case # 2</span></div>
|
||||
<div class="line"><span class="lineno"> 112</span> <span class="keyword">auto</span>* head2 = <span class="keyword">new</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>;</div>
|
||||
@@ -325,13 +344,12 @@ Here is the call graph for this function:</div>
|
||||
<div class="line"><span class="lineno"> 127</span> <span class="keyword">const</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <span class="keyword">const</span> median1 = <a class="code hl_function" href="#a5fefe132a0c3ee780ebc703f37ebce6a">search::median_search2::middleNode</a>(head2);</div>
|
||||
<div class="line"><span class="lineno"> 128</span> assert(4 == median1-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>); <span class="comment">// 4 is the value of the median node.</span></div>
|
||||
<div class="line"><span class="lineno"> 129</span> search::median_search2::deleteAll(head2);</div>
|
||||
<div class="line"><span class="lineno"> 130</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">"test case:2 passed\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 130</span> std::cout << <span class="stringliteral">"test case:2 passed\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 131</span> </div>
|
||||
<div class="line"><span class="lineno"> 132</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 passed--\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 132</span> std::cout << <span class="stringliteral">"--All tests passed--\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 133</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="amedian__search2_8cpp_html_a5fefe132a0c3ee780ebc703f37ebce6a"><div class="ttname"><a href="#a5fefe132a0c3ee780ebc703f37ebce6a">search::median_search2::middleNode</a></div><div class="ttdeci">ListNode * middleNode(ListNode *head)</div><div class="ttdef"><b>Definition</b> median_search2.cpp:59</div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_a58389d1d1fc5430c2f4ce7c5d5dc48b3"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">ListNode::val</a></div><div class="ttdeci">int val</div><div class="ttdoc">the value stored in the node</div><div class="ttdef"><b>Definition</b> median_search2.cpp:32</div></div>
|
||||
<div class="ttc" id="amedian__search2_8cpp_html_a5fefe132a0c3ee780ebc703f37ebce6a"><div class="ttname"><a href="#a5fefe132a0c3ee780ebc703f37ebce6a">search::median_search2::middleNode</a></div><div class="ttdeci">ListNode * middleNode(ListNode *head)</div><div class="ttdef"><b>Definition</b> <a href="../../d8/dfa/median__search2_8cpp_source.html#l00059">median_search2.cpp:59</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_a58389d1d1fc5430c2f4ce7c5d5dc48b3"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">ListNode::val</a></div><div class="ttdeci">int val</div><div class="ttdoc">the value stored in the node</div><div class="ttdef"><b>Definition</b> <a href="../../d8/dfa/median__search2_8cpp_source.html#l00032">median_search2.cpp:32</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<map id="search::median_search2::middleNode" name="search::median_search2::middleNode">
|
||||
<area shape="rect" id="Node000001" title=" " alt="" coords="5,29,169,70"/>
|
||||
<area shape="poly" id="edge1_Node000001_Node000001" title=" " alt="" coords="55,29,54,19,59,11,70,5,87,3,105,5,116,11,113,16,103,10,87,8,72,10,63,14,59,20,61,28"/>
|
||||
</map>
|
||||
@@ -1 +0,0 @@
|
||||
939e9c1e19260946cac2e7cf57b20b21
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
|
||||
-->
|
||||
<!-- Title: search::median_search2::middleNode Pages: 1 -->
|
||||
<svg width="131pt" height="57pt"
|
||||
viewBox="0.00 0.00 130.50 56.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
|
||||
|
||||
<style type="text/css"><![CDATA[
|
||||
.node, .edge {opacity: 0.7;}
|
||||
.node.selected, .edge.selected {opacity: 1;}
|
||||
.edge:hover path { stroke: red; }
|
||||
.edge:hover polygon { stroke: red; fill: red; }
|
||||
]]></style>
|
||||
<script type="application/ecmascript" xlink:href="../../svg.min.js"/>
|
||||
<svg id="graph" class="graph">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 52.5)">
|
||||
<title>search::median_search2::middleNode</title>
|
||||
<!-- Node1 -->
|
||||
<g id="Node000001" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_Node000001"><a xlink:title=" ">
|
||||
<polygon fill="#999999" stroke="#666666" points="122.5,-30.5 0,-30.5 0,0 122.5,0 122.5,-30.5"/>
|
||||
<text text-anchor="start" x="8" y="-17" font-family="Helvetica,sans-Serif" font-size="10.00">search::median_search2</text>
|
||||
<text text-anchor="middle" x="61.25" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">::middleNode</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node1->Node1 -->
|
||||
<g id="edge1_Node000001_Node000001" class="edge">
|
||||
<title>Node1->Node1</title>
|
||||
<g id="a_edge1_Node000001_Node000001"><a xlink:title=" ">
|
||||
<path fill="none" stroke="#63b8ff" d="M39.54,-30.99C35.11,-40.06 42.35,-48.5 61.25,-48.5 71.59,-48.5 78.43,-45.97 81.79,-42.2"/>
|
||||
<polygon fill="#63b8ff" stroke="#63b8ff" points="85.25,-42.8 82.8,-32.49 78.29,-42.08 85.25,-42.8"/>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</svg>
|
||||
|
||||
<style type='text/css'>
|
||||
<![CDATA[
|
||||
[data-mouse-over-selected='false'] { opacity: 0.7; }
|
||||
[data-mouse-over-selected='true'] { opacity: 1.0; }
|
||||
]]>
|
||||
</style>
|
||||
<script type="application/ecmascript"><![CDATA[
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
highlightEdges();
|
||||
highlightAdjacentNodes();
|
||||
});
|
||||
]]></script>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
|
||||
-->
|
||||
<!-- Title: search::median_search2::middleNode Pages: 1 -->
|
||||
<svg width="131pt" height="57pt"
|
||||
viewBox="0.00 0.00 130.50 56.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 52.5)">
|
||||
<title>search::median_search2::middleNode</title>
|
||||
<!-- Node1 -->
|
||||
<g id="Node000001" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_Node000001"><a xlink:title=" ">
|
||||
<polygon fill="#999999" stroke="#666666" points="122.5,-30.5 0,-30.5 0,0 122.5,0 122.5,-30.5"/>
|
||||
<text text-anchor="start" x="8" y="-17" font-family="Helvetica,sans-Serif" font-size="10.00">search::median_search2</text>
|
||||
<text text-anchor="middle" x="61.25" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">::middleNode</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node1->Node1 -->
|
||||
<g id="edge1_Node000001_Node000001" class="edge">
|
||||
<title>Node1->Node1</title>
|
||||
<g id="a_edge1_Node000001_Node000001"><a xlink:title=" ">
|
||||
<path fill="none" stroke="#63b8ff" d="M39.54,-30.99C35.11,-40.06 42.35,-48.5 61.25,-48.5 71.59,-48.5 78.43,-45.97 81.79,-42.2"/>
|
||||
<polygon fill="#63b8ff" stroke="#63b8ff" points="85.25,-42.8 82.8,-32.49 78.29,-42.08 85.25,-42.8"/>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.4 KiB |
@@ -1,5 +0,0 @@
|
||||
<map id="main" name="main">
|
||||
<area shape="rect" id="Node000001" title="Main function." alt="" coords="5,5,55,31"/>
|
||||
<area shape="rect" id="Node000002" href="$d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" title="Self-test implementations." alt="" coords="103,5,146,31"/>
|
||||
<area shape="poly" id="edge1_Node000001_Node000002" title=" " alt="" coords="55,16,87,16,87,21,55,21"/>
|
||||
</map>
|
||||
@@ -1 +0,0 @@
|
||||
97a4f15fdb0c94b992ad88c19eced9f9
|
||||
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
|
||||
-->
|
||||
<!-- Title: main Pages: 1 -->
|
||||
<svg width="114pt" height="27pt"
|
||||
viewBox="0.00 0.00 113.50 27.25" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
|
||||
|
||||
<style type="text/css"><![CDATA[
|
||||
.node, .edge {opacity: 0.7;}
|
||||
.node.selected, .edge.selected {opacity: 1;}
|
||||
.edge:hover path { stroke: red; }
|
||||
.edge:hover polygon { stroke: red; fill: red; }
|
||||
]]></style>
|
||||
<script type="application/ecmascript" xlink:href="../../svg.min.js"/>
|
||||
<svg id="graph" class="graph">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 23.25)">
|
||||
<title>main</title>
|
||||
<!-- Node1 -->
|
||||
<g id="Node000001" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_Node000001"><a xlink:title="Main function.">
|
||||
<polygon fill="#999999" stroke="#666666" points="37,-19.25 0,-19.25 0,0 37,0 37,-19.25"/>
|
||||
<text text-anchor="middle" x="18.5" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">main</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node2 -->
|
||||
<g id="Node000002" class="node">
|
||||
<title>Node2</title>
|
||||
<g id="a_Node000002"><a xlink:href="../../d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" target="_top" xlink:title="Self-test implementations.">
|
||||
<polygon fill="white" stroke="#666666" points="105.5,-19.25 73,-19.25 73,0 105.5,0 105.5,-19.25"/>
|
||||
<text text-anchor="middle" x="89.25" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">test</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node1->Node2 -->
|
||||
<g id="edge1_Node000001_Node000002" class="edge">
|
||||
<title>Node1->Node2</title>
|
||||
<g id="a_edge1_Node000001_Node000002"><a xlink:title=" ">
|
||||
<path fill="none" stroke="#63b8ff" d="M37.2,-9.62C44.58,-9.62 53.31,-9.62 61.45,-9.62"/>
|
||||
<polygon fill="#63b8ff" stroke="#63b8ff" points="61.2,-13.13 71.2,-9.63 61.2,-6.13 61.2,-13.13"/>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</svg>
|
||||
|
||||
<style type='text/css'>
|
||||
<![CDATA[
|
||||
[data-mouse-over-selected='false'] { opacity: 0.7; }
|
||||
[data-mouse-over-selected='true'] { opacity: 1.0; }
|
||||
]]>
|
||||
</style>
|
||||
<script type="application/ecmascript"><![CDATA[
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
highlightEdges();
|
||||
highlightAdjacentNodes();
|
||||
});
|
||||
]]></script>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.4 KiB |
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
|
||||
-->
|
||||
<!-- Title: main Pages: 1 -->
|
||||
<svg width="114pt" height="27pt"
|
||||
viewBox="0.00 0.00 113.50 27.25" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 23.25)">
|
||||
<title>main</title>
|
||||
<!-- Node1 -->
|
||||
<g id="Node000001" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_Node000001"><a xlink:title="Main function.">
|
||||
<polygon fill="#999999" stroke="#666666" points="37,-19.25 0,-19.25 0,0 37,0 37,-19.25"/>
|
||||
<text text-anchor="middle" x="18.5" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">main</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node2 -->
|
||||
<g id="Node000002" class="node">
|
||||
<title>Node2</title>
|
||||
<g id="a_Node000002"><a xlink:href="../../d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" target="_top" xlink:title="Self-test implementations.">
|
||||
<polygon fill="white" stroke="#666666" points="105.5,-19.25 73,-19.25 73,0 105.5,0 105.5,-19.25"/>
|
||||
<text text-anchor="middle" x="89.25" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">test</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node1->Node2 -->
|
||||
<g id="edge1_Node000001_Node000002" class="edge">
|
||||
<title>Node1->Node2</title>
|
||||
<g id="a_edge1_Node000001_Node000002"><a xlink:title=" ">
|
||||
<path fill="none" stroke="#63b8ff" d="M37.2,-9.62C44.58,-9.62 53.31,-9.62 61.45,-9.62"/>
|
||||
<polygon fill="#63b8ff" stroke="#63b8ff" points="61.2,-13.13 71.2,-9.63 61.2,-6.13 61.2,-13.13"/>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.6 KiB |
251
d8/dfa/median__search2_8cpp_source.html
Normal file
251
d8/dfa/median__search2_8cpp_source.html
Normal file
@@ -0,0 +1,251 @@
|
||||
<!-- 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.12.0"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>TheAlgorithms/C++: search/median_search2.cpp Source File</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="../../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/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"> 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.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('d8/dfa/median__search2_8cpp_source.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="headertitle"><div class="title">median_search2.cpp</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<a href="../../d8/dfa/median__search2_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
|
||||
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span><span class="preprocessor">#include <cassert></span> </div>
|
||||
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span><span class="preprocessor">#include <iostream></span> </div>
|
||||
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> </div>
|
||||
<div class="foldopen" id="foldopen00031" data-start="{" data-end="};">
|
||||
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"><a class="line" href="../../d7/da4/struct_list_node.html"> 31</a></span><span class="keyword">struct </span><a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a> {</div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"><a class="line" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3"> 32</a></span> <span class="keywordtype">int</span> <a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>{0}; </div>
|
||||
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"><a class="line" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1"> 33</a></span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>{<span class="keyword">nullptr</span>}; </div>
|
||||
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"><a class="line" href="../../d7/da4/struct_list_node.html#a3cfee2eb667c332dc32595208164ef0a"> 34</a></span> <a class="code hl_function" href="../../d7/da4/struct_list_node.html#a3cfee2eb667c332dc32595208164ef0a">ListNode</a>() = <span class="keywordflow">default</span>; </div>
|
||||
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"><a class="line" href="../../d7/da4/struct_list_node.html#aaad9b553e2f936726f5b35ff2734125d"> 35</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="../../d7/da4/struct_list_node.html#aaad9b553e2f936726f5b35ff2734125d">ListNode</a>(<span class="keywordtype">int</span> x)</div>
|
||||
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> : <a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>(x) {} </div>
|
||||
<div class="foldopen" id="foldopen00037" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"><a class="line" href="../../d7/da4/struct_list_node.html#afc97c5b9d2e7cc82d0718245688f6ff9"> 37</a></span> <a class="code hl_function" href="../../d7/da4/struct_list_node.html#afc97c5b9d2e7cc82d0718245688f6ff9">ListNode</a>(<span class="keywordtype">int</span> x, <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>)</div>
|
||||
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> : <a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>(x),</div>
|
||||
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> <a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>(<a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>) {</div>
|
||||
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> } </div>
|
||||
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span>};</div>
|
||||
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> </div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d9/dca/namespacesearch.html">search</a> {</div>
|
||||
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span><span class="keyword">namespace </span>median_search2 {</div>
|
||||
<div class="foldopen" id="foldopen00059" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"><a class="line" href="../../d8/dfa/median__search2_8cpp.html#a5fefe132a0c3ee780ebc703f37ebce6a"> 59</a></span><a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <a class="code hl_function" href="../../d8/dfa/median__search2_8cpp.html#a5fefe132a0c3ee780ebc703f37ebce6a">middleNode</a>(<a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* head) {</div>
|
||||
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="keywordflow">if</span> (!head) {</div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
|
||||
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> }</div>
|
||||
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> </div>
|
||||
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <span class="comment">// Fast and slow pointers</span></div>
|
||||
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* fastptr = <span class="keyword">nullptr</span>;</div>
|
||||
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* slowptr = fastptr = head;</div>
|
||||
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> </div>
|
||||
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> <span class="comment">// fast jumps 2 while slow jumps 1</span></div>
|
||||
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="keywordflow">while</span> (fastptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> && fastptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>) {</div>
|
||||
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> slowptr = slowptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>;</div>
|
||||
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> fastptr = fastptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>;</div>
|
||||
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> }</div>
|
||||
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> </div>
|
||||
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <span class="keywordflow">return</span> (fastptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a>) ? slowptr-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> : slowptr;</div>
|
||||
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span>}</div>
|
||||
</div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> </div>
|
||||
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span><span class="keywordtype">void</span> deleteAll(<span class="keyword">const</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <span class="keyword">const</span> head) {</div>
|
||||
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <span class="keywordflow">if</span> (head) {</div>
|
||||
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> deleteAll(head->next);</div>
|
||||
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <span class="keyword">delete</span> head;</div>
|
||||
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> }</div>
|
||||
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span>}</div>
|
||||
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span>} <span class="comment">// namespace median_search2</span></div>
|
||||
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span>} <span class="comment">// namespace search</span></div>
|
||||
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> </div>
|
||||
<div class="foldopen" id="foldopen00090" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"><a class="line" href="../../d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d"> 90</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>() {</div>
|
||||
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> <span class="keyword">auto</span>* head1 = <span class="keyword">new</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>;</div>
|
||||
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> head1-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a> = 1;</div>
|
||||
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> </div>
|
||||
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* temp = head1;</div>
|
||||
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 2; i < 6; ++i) {</div>
|
||||
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <span class="comment">// Allocate next</span></div>
|
||||
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="keyword">auto</span>* temp1 = <span class="keyword">new</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>;</div>
|
||||
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> temp1-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a> = i;</div>
|
||||
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> </div>
|
||||
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> <span class="comment">// Advance</span></div>
|
||||
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> temp-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> = temp1;</div>
|
||||
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> temp = temp1;</div>
|
||||
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> }</div>
|
||||
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> temp-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> = <span class="keyword">nullptr</span>;</div>
|
||||
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> </div>
|
||||
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <span class="keyword">const</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <span class="keyword">const</span> median = search::median_search2::middleNode(head1);</div>
|
||||
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> assert(3 == median-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>); <span class="comment">// 3 is the value of the median node.</span></div>
|
||||
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> search::median_search2::deleteAll(head1);</div>
|
||||
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> std::cout << <span class="stringliteral">"test case:1 passed\n"</span>;</div>
|
||||
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> </div>
|
||||
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> <span class="comment">// Test case # 2</span></div>
|
||||
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <span class="keyword">auto</span>* head2 = <span class="keyword">new</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>;</div>
|
||||
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> head2-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a> = 1;</div>
|
||||
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> </div>
|
||||
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* temp2 = head2;</div>
|
||||
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 2; i < 7; ++i) {</div>
|
||||
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> <span class="comment">// Allocate next</span></div>
|
||||
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> <span class="keyword">auto</span>* temp3 = <span class="keyword">new</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>;</div>
|
||||
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> temp3-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a> = i;</div>
|
||||
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> </div>
|
||||
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> <span class="comment">// Advance</span></div>
|
||||
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> temp2-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> = temp3;</div>
|
||||
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> temp2 = temp3;</div>
|
||||
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> }</div>
|
||||
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> temp2-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">next</a> = <span class="keyword">nullptr</span>;</div>
|
||||
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> </div>
|
||||
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> <span class="keyword">const</span> <a class="code hl_struct" href="../../d7/da4/struct_list_node.html">ListNode</a>* <span class="keyword">const</span> median1 = search::median_search2::middleNode(head2);</div>
|
||||
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> assert(4 == median1-><a class="code hl_variable" href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">val</a>); <span class="comment">// 4 is the value of the median node.</span></div>
|
||||
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span> search::median_search2::deleteAll(head2);</div>
|
||||
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span> std::cout << <span class="stringliteral">"test case:2 passed\n"</span>;</div>
|
||||
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> </div>
|
||||
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> std::cout << <span class="stringliteral">"--All tests passed--\n"</span>;</div>
|
||||
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span>}</div>
|
||||
</div>
|
||||
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> </div>
|
||||
<div class="foldopen" id="foldopen00139" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"><a class="line" href="../../d8/dfa/median__search2_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4"> 139</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="../../d8/dfa/median__search2_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
|
||||
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> <a class="code hl_function" href="../../d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
||||
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"> 141</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno"> 142</span>}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ttc" id="amedian__search2_8cpp_html_a5fefe132a0c3ee780ebc703f37ebce6a"><div class="ttname"><a href="../../d8/dfa/median__search2_8cpp.html#a5fefe132a0c3ee780ebc703f37ebce6a">search::median_search2::middleNode</a></div><div class="ttdeci">ListNode * middleNode(ListNode *head)</div><div class="ttdef"><b>Definition</b> <a href="#l00059">median_search2.cpp:59</a></div></div>
|
||||
<div class="ttc" id="amedian__search2_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d8/dfa/median__search2_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> <a href="#l00090">median_search2.cpp:90</a></div></div>
|
||||
<div class="ttc" id="amedian__search2_8cpp_html_ae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../d8/dfa/median__search2_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdoc">Main function.</div><div class="ttdef"><b>Definition</b> <a href="#l00139">median_search2.cpp:139</a></div></div>
|
||||
<div class="ttc" id="anamespacesearch_html"><div class="ttname"><a href="../../d9/dca/namespacesearch.html">search</a></div><div class="ttdoc">for std::assert</div><div class="ttdef"><b>Definition</b> <a href="../../df/dd5/binary__search_8cpp_source.html#l00047">binary_search.cpp:47</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html"><div class="ttname"><a href="../../d7/da4/struct_list_node.html">ListNode</a></div><div class="ttdoc">for IO operations</div><div class="ttdef"><b>Definition</b> <a href="#l00031">median_search2.cpp:31</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_a3cfee2eb667c332dc32595208164ef0a"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#a3cfee2eb667c332dc32595208164ef0a">ListNode::ListNode</a></div><div class="ttdeci">ListNode()=default</div><div class="ttdoc">default constructor</div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_a58389d1d1fc5430c2f4ce7c5d5dc48b3"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#a58389d1d1fc5430c2f4ce7c5d5dc48b3">ListNode::val</a></div><div class="ttdeci">int val</div><div class="ttdoc">the value stored in the node</div><div class="ttdef"><b>Definition</b> <a href="#l00032">median_search2.cpp:32</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_aaad9b553e2f936726f5b35ff2734125d"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#aaad9b553e2f936726f5b35ff2734125d">ListNode::ListNode</a></div><div class="ttdeci">ListNode(int x)</div><div class="ttdoc">constructor with value for node->val provided</div><div class="ttdef"><b>Definition</b> <a href="#l00035">median_search2.cpp:35</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_ad78b392c2ddc25c3243d0c2f30692fb1"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#ad78b392c2ddc25c3243d0c2f30692fb1">ListNode::next</a></div><div class="ttdeci">ListNode * next</div><div class="ttdoc">pointer to the next node</div><div class="ttdef"><b>Definition</b> <a href="#l00033">median_search2.cpp:33</a></div></div>
|
||||
<div class="ttc" id="astruct_list_node_html_afc97c5b9d2e7cc82d0718245688f6ff9"><div class="ttname"><a href="../../d7/da4/struct_list_node.html#afc97c5b9d2e7cc82d0718245688f6ff9">ListNode::ListNode</a></div><div class="ttdeci">ListNode(int x, ListNode *next)</div><div class="ttdoc">constructor with values provided for node->val and node->next</div><div class="ttdef"><b>Definition</b> <a href="#l00037">median_search2.cpp:37</a></div></div>
|
||||
</div><!-- fragment --></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_19b2bf9199a15c634a08b1ede1dd896a.html">search</a></li><li class="navelem"><a class="el" href="../../d8/dfa/median__search2_8cpp.html">median_search2.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>
|
||||
Reference in New Issue
Block a user