mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
375 lines
31 KiB
HTML
375 lines
31 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">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.2"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: misc/cantor_set.c File Reference</title>
|
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../jquery.js"></script>
|
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../resize.js"></script>
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
<script type="text/javascript" src="../../navtree.js"></script>
|
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
|
<script type="text/javascript" src="../../search/search.js"></script>
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
|
jax: ["input/TeX","output/HTML-CSS"],
|
|
});
|
|
</script>
|
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<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.9.2 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="../../menudata.js"></script>
|
|
<script type="text/javascript" src="../../menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('dc/d80/cantor__set_8c.html','../../'); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#nested-classes">Data Structures</a> |
|
|
<a href="#typedef-members">Typedefs</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">cantor_set.c File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>Program to generate <a href="https://en.wikipedia.org/wiki/Cantor_set" target="_blank">Cantor ternary set</a>
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <stdio.h></code><br />
|
|
<code>#include <stdlib.h></code><br />
|
|
<code>#include <string.h></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for cantor_set.c:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/ddc/cantor__set_8c__incl.svg" width="251" height="112"><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>
|
|
Data Structures</h2></td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/dd7/struct__cantor__set.html">_cantor_set</a></td></tr>
|
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">structure to define Cantor set <a href="../../d9/dd7/struct__cantor__set.html#details">More...</a><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="typedef-members" name="typedef-members"></a>
|
|
Typedefs</h2></td></tr>
|
|
<tr class="memitem:a2b95c356aff8a282eaad255008fa5a94"><td class="memItemLeft" align="right" valign="top"><a id="a2b95c356aff8a282eaad255008fa5a94" name="a2b95c356aff8a282eaad255008fa5a94"></a>
|
|
typedef struct <a class="el" href="../../d9/dd7/struct__cantor__set.html">_cantor_set</a> </td><td class="memItemRight" valign="bottom"><b>CantorSet</b></td></tr>
|
|
<tr class="memdesc:a2b95c356aff8a282eaad255008fa5a94"><td class="mdescLeft"> </td><td class="mdescRight">structure to define Cantor set <br /></td></tr>
|
|
<tr class="separator:a2b95c356aff8a282eaad255008fa5a94"><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:a1f156d2b53b80305bd2fa3ff5fdf3c97"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97">propagate</a> (<a class="el" href="../../dc/d80/cantor__set_8c.html#a2b95c356aff8a282eaad255008fa5a94">CantorSet</a> *head)</td></tr>
|
|
<tr class="memdesc:a1f156d2b53b80305bd2fa3ff5fdf3c97"><td class="mdescLeft"> </td><td class="mdescRight">Iterative constructor of all sets in the current level. <a href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97">More...</a><br /></td></tr>
|
|
<tr class="separator:a1f156d2b53b80305bd2fa3ff5fdf3c97"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a75ee530cd7148a63249784ad3dda8fab"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d80/cantor__set_8c.html#a75ee530cd7148a63249784ad3dda8fab">print</a> (<a class="el" href="../../dc/d80/cantor__set_8c.html#a2b95c356aff8a282eaad255008fa5a94">CantorSet</a> *head)</td></tr>
|
|
<tr class="memdesc:a75ee530cd7148a63249784ad3dda8fab"><td class="mdescLeft"> </td><td class="mdescRight">Print sets in the current range to <code>stdout</code> <a href="../../dc/d80/cantor__set_8c.html#a75ee530cd7148a63249784ad3dda8fab">More...</a><br /></td></tr>
|
|
<tr class="separator:a75ee530cd7148a63249784ad3dda8fab"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a85df3c64a683100ac6246e1e034df43d"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d80/cantor__set_8c.html#a85df3c64a683100ac6246e1e034df43d">free_memory</a> (<a class="el" href="../../dc/d80/cantor__set_8c.html#a2b95c356aff8a282eaad255008fa5a94">CantorSet</a> *head)</td></tr>
|
|
<tr class="memdesc:a85df3c64a683100ac6246e1e034df43d"><td class="mdescLeft"> </td><td class="mdescRight">Clear memory allocated by <a class="el" href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97" title="Iterative constructor of all sets in the current level.">propagate</a> function. <a href="../../dc/d80/cantor__set_8c.html#a85df3c64a683100ac6246e1e034df43d">More...</a><br /></td></tr>
|
|
<tr class="separator:a85df3c64a683100ac6246e1e034df43d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:abf9e6b7e6f15df4b525a2e7705ba3089"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d80/cantor__set_8c.html#abf9e6b7e6f15df4b525a2e7705ba3089">main</a> (int argc, char const *argv[])</td></tr>
|
|
<tr class="memdesc:abf9e6b7e6f15df4b525a2e7705ba3089"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../dc/d80/cantor__set_8c.html#abf9e6b7e6f15df4b525a2e7705ba3089">More...</a><br /></td></tr>
|
|
<tr class="separator:abf9e6b7e6f15df4b525a2e7705ba3089"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p >Program to generate <a href="https://en.wikipedia.org/wiki/Cantor_set" target="_blank">Cantor ternary set</a> </p>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a85df3c64a683100ac6246e1e034df43d" name="a85df3c64a683100ac6246e1e034df43d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a85df3c64a683100ac6246e1e034df43d">◆ </a></span>free_memory()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void free_memory </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../dc/d80/cantor__set_8c.html#a2b95c356aff8a282eaad255008fa5a94">CantorSet</a> * </td>
|
|
<td class="paramname"><em>head</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Clear memory allocated by <a class="el" href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97" title="Iterative constructor of all sets in the current level.">propagate</a> function. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">head</td><td>pointer to first allocated instance. </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<div class="fragment"><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">if</span> (!head)</div>
|
|
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> <span class="keywordflow">return</span>;</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="keywordflow">if</span> (head->next)</div>
|
|
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <a class="code hl_function" href="../../dc/d80/cantor__set_8c.html#a85df3c64a683100ac6246e1e034df43d">free_memory</a>(head->next);</div>
|
|
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> </div>
|
|
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(head);</div>
|
|
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span>}</div>
|
|
<div class="ttc" id="acantor__set_8c_html_a85df3c64a683100ac6246e1e034df43d"><div class="ttname"><a href="../../dc/d80/cantor__set_8c.html#a85df3c64a683100ac6246e1e034df43d">free_memory</a></div><div class="ttdeci">void free_memory(CantorSet *head)</div><div class="ttdoc">Clear memory allocated by propagate function.</div><div class="ttdef"><b>Definition:</b> cantor_set.c:72</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</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="../../dc/d80/cantor__set_8c_a85df3c64a683100ac6246e1e034df43d_cgraph.svg" width="110" height="62"><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="abf9e6b7e6f15df4b525a2e7705ba3089" name="abf9e6b7e6f15df4b525a2e7705ba3089"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#abf9e6b7e6f15df4b525a2e7705ba3089">◆ </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">int </td>
|
|
<td class="paramname"><em>argc</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">char const * </td>
|
|
<td class="paramname"><em>argv</em>[] </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Main function. </p>
|
|
<div class="fragment"><div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span>{</div>
|
|
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <span class="keywordtype">int</span> start_num, end_num, levels;</div>
|
|
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> </div>
|
|
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> <span class="keywordflow">if</span> (argc < 2)</div>
|
|
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> {</div>
|
|
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> printf(<span class="stringliteral">"Enter 3 arguments: start_num \t end_num \t levels\n"</span>);</div>
|
|
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> scanf(<span class="stringliteral">"%d %d %d"</span>, &start_num, &end_num, &levels);</div>
|
|
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> }</div>
|
|
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> <span class="keywordflow">else</span></div>
|
|
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> {</div>
|
|
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> start_num = atoi(argv[1]);</div>
|
|
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> end_num = atoi(argv[2]);</div>
|
|
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> levels = atoi(argv[3]);</div>
|
|
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> }</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="keywordflow">if</span> (start_num < 0 || end_num < 0 || levels < 0)</div>
|
|
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> {</div>
|
|
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> fprintf(stderr, <span class="stringliteral">"All numbers must be positive\n"</span>);</div>
|
|
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <span class="keywordflow">return</span> -1;</div>
|
|
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</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> <a class="code hl_struct" href="../../d9/dd7/struct__cantor__set.html">CantorSet</a> head = {.start = start_num, .end = end_num, .next = NULL};</div>
|
|
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> </div>
|
|
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> <span class="comment">// loop to propagate each level from top to bottom</span></div>
|
|
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < levels; i++)</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> printf(<span class="stringliteral">"Level %d\t"</span>, i);</div>
|
|
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <a class="code hl_function" href="../../dc/d80/cantor__set_8c.html#a75ee530cd7148a63249784ad3dda8fab">print</a>(&head);</div>
|
|
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> <a class="code hl_function" href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97">propagate</a>(&head);</div>
|
|
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> printf(<span class="stringliteral">"\n"</span>);</div>
|
|
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> }</div>
|
|
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> printf(<span class="stringliteral">"Level %d\t"</span>, levels);</div>
|
|
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> <a class="code hl_function" href="../../dc/d80/cantor__set_8c.html#a75ee530cd7148a63249784ad3dda8fab">print</a>(&head);</div>
|
|
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> </div>
|
|
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> <span class="comment">// delete all memory allocated</span></div>
|
|
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> <a class="code hl_function" href="../../dc/d80/cantor__set_8c.html#a85df3c64a683100ac6246e1e034df43d">free_memory</a>(head.next);</div>
|
|
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> </div>
|
|
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span>}</div>
|
|
<div class="ttc" id="acantor__set_8c_html_a1f156d2b53b80305bd2fa3ff5fdf3c97"><div class="ttname"><a href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97">propagate</a></div><div class="ttdeci">void propagate(CantorSet *head)</div><div class="ttdoc">Iterative constructor of all sets in the current level.</div><div class="ttdef"><b>Definition:</b> cantor_set.c:23</div></div>
|
|
<div class="ttc" id="acantor__set_8c_html_a75ee530cd7148a63249784ad3dda8fab"><div class="ttname"><a href="../../dc/d80/cantor__set_8c.html#a75ee530cd7148a63249784ad3dda8fab">print</a></div><div class="ttdeci">void print(CantorSet *head)</div><div class="ttdoc">Print sets in the current range to stdout</div><div class="ttdef"><b>Definition:</b> cantor_set.c:55</div></div>
|
|
<div class="ttc" id="astruct__cantor__set_html"><div class="ttname"><a href="../../d9/dd7/struct__cantor__set.html">_cantor_set</a></div><div class="ttdoc">structure to define Cantor set</div><div class="ttdef"><b>Definition:</b> cantor_set.c:12</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="../../dc/d80/cantor__set_8c_abf9e6b7e6f15df4b525a2e7705ba3089_cgraph.svg" width="334" height="187"><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="a75ee530cd7148a63249784ad3dda8fab" name="a75ee530cd7148a63249784ad3dda8fab"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a75ee530cd7148a63249784ad3dda8fab">◆ </a></span>print()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void print </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../dc/d80/cantor__set_8c.html#a2b95c356aff8a282eaad255008fa5a94">CantorSet</a> * </td>
|
|
<td class="paramname"><em>head</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Print sets in the current range to <code>stdout</code> </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">head</td><td>pointer to first set in the current level </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<div class="fragment"><div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span>{</div>
|
|
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <a class="code hl_struct" href="../../d9/dd7/struct__cantor__set.html">CantorSet</a> *temp = head;</div>
|
|
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordflow">while</span> (temp != NULL) <span class="comment">// print while a valid set is found</span></div>
|
|
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> {</div>
|
|
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> printf(<span class="stringliteral">"\t"</span>);</div>
|
|
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> printf(<span class="stringliteral">"[%lf] -- "</span>, temp->start);</div>
|
|
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> printf(<span class="stringliteral">"[%lf]"</span>, temp->end);</div>
|
|
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> temp = temp->next;</div>
|
|
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> }</div>
|
|
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> </div>
|
|
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> printf(<span class="stringliteral">"\n"</span>);</div>
|
|
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a1f156d2b53b80305bd2fa3ff5fdf3c97" name="a1f156d2b53b80305bd2fa3ff5fdf3c97"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a1f156d2b53b80305bd2fa3ff5fdf3c97">◆ </a></span>propagate()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void propagate </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="../../dc/d80/cantor__set_8c.html#a2b95c356aff8a282eaad255008fa5a94">CantorSet</a> * </td>
|
|
<td class="paramname"><em>head</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Iterative constructor of all sets in the current level. </p>
|
|
<p >This function dynamically allocates memory when creating new sets. These are freed by the function <a class="el" href="../../dc/d80/cantor__set_8c.html#a85df3c64a683100ac6246e1e034df43d" title="Clear memory allocated by propagate function.">free_memory</a>. </p><dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">head</td><td>pointer to interval set instance to update </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<div class="fragment"><div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span>{</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> <span class="comment">// if input is NULL, ignore the process</span></div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> <span class="keywordflow">if</span> (head == NULL)</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> <span class="keywordflow">return</span>;</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> </div>
|
|
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> <a class="code hl_struct" href="../../d9/dd7/struct__cantor__set.html">CantorSet</a> *temp = head; <span class="comment">// local pointer to track propagation</span></div>
|
|
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> </div>
|
|
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> <span class="comment">// create new node for the new set</span></div>
|
|
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> <a class="code hl_struct" href="../../d9/dd7/struct__cantor__set.html">CantorSet</a> *<a class="code hl_function" href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a> = (<a class="code hl_struct" href="../../d9/dd7/struct__cantor__set.html">CantorSet</a> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<a class="code hl_struct" href="../../d9/dd7/struct__cantor__set.html">CantorSet</a>));</div>
|
|
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> </div>
|
|
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> <span class="comment">// get 1/3rd of interval</span></div>
|
|
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> <span class="keywordtype">double</span> diff = (((temp->end) - (temp->start)) / 3);</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> </div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> <span class="comment">// update interval ranges</span></div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> <a class="code hl_function" href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a>->end = temp->end;</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> temp->end = ((temp->start) + diff);</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> <a class="code hl_function" href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a>->start = (<a class="code hl_function" href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a>->end) - diff;</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> <span class="comment">// update pointer to next set in this level</span></div>
|
|
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> <a class="code hl_function" href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a>->next = temp->next;</div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> </div>
|
|
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> <span class="comment">// point to next set</span></div>
|
|
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> temp->next = <a class="code hl_function" href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a>;</div>
|
|
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> </div>
|
|
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> <span class="comment">// create next set</span></div>
|
|
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> <a class="code hl_function" href="../../dc/d80/cantor__set_8c.html#a1f156d2b53b80305bd2fa3ff5fdf3c97">propagate</a>(temp->next->next);</div>
|
|
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span>}</div>
|
|
<div class="ttc" id="abinary__search__tree_8c_html_adf2169c1008551b20c4a59fcf0c9ab3b"><div class="ttname"><a href="../../da/d02/binary__search__tree_8c.html#adf2169c1008551b20c4a59fcf0c9ab3b">newNode</a></div><div class="ttdeci">node * newNode(int data)</div><div class="ttdoc">The node constructor, which receives the key value input and returns a node pointer.</div><div class="ttdef"><b>Definition:</b> binary_search_tree.c:28</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</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="../../dc/d80/cantor__set_8c_a1f156d2b53b80305bd2fa3ff5fdf3c97_cgraph.svg" width="215" height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="../../dir_a52f4d3d586a58b02f3a4ddf0a992157.html">misc</a></li><li class="navelem"><a class="el" href="../../dc/d80/cantor__set_8c.html">cantor_set.c</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|