mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-12 14:47:08 +03:00
314 lines
18 KiB
HTML
314 lines
18 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=9"/>
|
|
<meta name="generator" content="Doxygen 1.9.1"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: Misc</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.1 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(function(){initNavTree('d1/ded/group__misc.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="#func-members">Functions</a> </div>
|
|
<div class="headertitle">
|
|
<div class="title">Misc</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>variable upto which prime numbers are to be found out
|
|
<a href="#details">More...</a></p>
|
|
<table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:gac1a7a8e00eeb590511465c28fae16e54"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/ded/group__misc.html#gac1a7a8e00eeb590511465c28fae16e54">prime</a> (int *p)</td></tr>
|
|
<tr class="memdesc:gac1a7a8e00eeb590511465c28fae16e54"><td class="mdescLeft"> </td><td class="mdescRight">Prime Sieve works in O(nlogn) time. <a href="../../d1/ded/group__misc.html#gac1a7a8e00eeb590511465c28fae16e54">More...</a><br /></td></tr>
|
|
<tr class="separator:gac1a7a8e00eeb590511465c28fae16e54"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga6f8e8c9d25b5891d57e588d80d75028a"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/ded/group__misc.html#ga6f8e8c9d25b5891d57e588d80d75028a">count</a> (int *arr, const int size)</td></tr>
|
|
<tr class="memdesc:ga6f8e8c9d25b5891d57e588d80d75028a"><td class="mdescLeft"> </td><td class="mdescRight">Count func counts the number of prime numbers. <a href="../../d1/ded/group__misc.html#ga6f8e8c9d25b5891d57e588d80d75028a">More...</a><br /></td></tr>
|
|
<tr class="separator:ga6f8e8c9d25b5891d57e588d80d75028a"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gaa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/ded/group__misc.html#gaa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
|
<tr class="memdesc:gaa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Test implementations. <a href="../../d1/ded/group__misc.html#gaa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
|
<tr class="separator:gaa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gac0f2228420376f4db7e1274f2b41667c"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/ded/group__misc.html#gac0f2228420376f4db7e1274f2b41667c">main</a> (int argc, const char *argv[])</td></tr>
|
|
<tr class="memdesc:gac0f2228420376f4db7e1274f2b41667c"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../d1/ded/group__misc.html#gac0f2228420376f4db7e1274f2b41667c">More...</a><br /></td></tr>
|
|
<tr class="separator:gac0f2228420376f4db7e1274f2b41667c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<p>variable upto which prime numbers are to be found out </p>
|
|
<h2 class="groupheader">Function Documentation</h2>
|
|
<a id="ga6f8e8c9d25b5891d57e588d80d75028a"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga6f8e8c9d25b5891d57e588d80d75028a">◆ </a></span>count()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int count </td>
|
|
<td>(</td>
|
|
<td class="paramtype">int * </td>
|
|
<td class="paramname"><em>arr</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const int </td>
|
|
<td class="paramname"><em>size</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Count func counts the number of prime numbers. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">arr</td><td>contains the prime numbers </td></tr>
|
|
<tr><td class="paramname">size</td><td>denotes upto which prime numbers are to be found out </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>count of prime numbers </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  {</div>
|
|
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="keywordtype">int</span> k=0;</div>
|
|
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<=size;i++){</div>
|
|
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  <span class="keywordflow">if</span>(arr[i]==1){</div>
|
|
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  k++;</div>
|
|
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  }</div>
|
|
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  }</div>
|
|
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="keywordflow">return</span> k;</div>
|
|
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="gac0f2228420376f4db7e1274f2b41667c"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#gac0f2228420376f4db7e1274f2b41667c">◆ </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">const char * </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>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">argc</td><td>commandline argument count (ignored) </td></tr>
|
|
<tr><td class="paramname">argv</td><td>commandline array of arguments (ignored) </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> {</div>
|
|
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <a class="code" href="../../d1/ded/group__misc.html#gaa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// execute the tests</span></div>
|
|
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span> }</div>
|
|
<div class="ttc" id="agroup__misc_html_gaa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d1/ded/group__misc.html#gaa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Test implementations.</div><div class="ttdef"><b>Definition:</b> prime_seive.c:56</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="../../d1/ded/group__misc_gac0f2228420376f4db7e1274f2b41667c_cgraph.svg" width="256" height="88"><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="gac1a7a8e00eeb590511465c28fae16e54"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#gac1a7a8e00eeb590511465c28fae16e54">◆ </a></span>prime()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void prime </td>
|
|
<td>(</td>
|
|
<td class="paramtype">int * </td>
|
|
<td class="paramname"><em>p</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Prime Sieve works in O(nlogn) time. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">p</td><td>array to be updated </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> {</div>
|
|
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  <span class="keywordflow">for</span>(<span class="keywordtype">long</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> i=3;i<=<a class="code" href="../../db/dd5/prime__seive_8c.html#ac1215a37edfa07d37edf6ec65f2235c7">MAX_SIZE</a>;i+=2) { p[i]=1; }</div>
|
|
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span>  <span class="keywordflow">for</span>(<span class="keywordtype">long</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> i=3;i<=<a class="code" href="../../db/dd5/prime__seive_8c.html#ac1215a37edfa07d37edf6ec65f2235c7">MAX_SIZE</a>;i+=2)</div>
|
|
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>  {</div>
|
|
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>  <span class="keywordflow">if</span>(p[i]==1) {</div>
|
|
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>  <span class="keywordflow">for</span>(<span class="keywordtype">long</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> j=i*i;j<=<a class="code" href="../../db/dd5/prime__seive_8c.html#ac1215a37edfa07d37edf6ec65f2235c7">MAX_SIZE</a>;j+=i) {</div>
|
|
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span>  p[j]=0;</div>
|
|
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  }</div>
|
|
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  }</div>
|
|
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  }</div>
|
|
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  p[2]=1;</div>
|
|
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  p[0]=p[1]=0; </div>
|
|
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span> }</div>
|
|
<div class="ttc" id="aprime__seive_8c_html_ac1215a37edfa07d37edf6ec65f2235c7"><div class="ttname"><a href="../../db/dd5/prime__seive_8c.html#ac1215a37edfa07d37edf6ec65f2235c7">MAX_SIZE</a></div><div class="ttdeci">const unsigned long long MAX_SIZE</div><div class="ttdoc">for assert for standard input output for general purpose standard library</div><div class="ttdef"><b>Definition:</b> prime_seive.c:11</div></div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="gaa8dca7b867074164d5f45b0f3851269d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#gaa8dca7b867074164d5f45b0f3851269d">◆ </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="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">static</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test implementations. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> {</div>
|
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="comment">// Test Case 1</span></div>
|
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> size = 10; <span class="comment">/* array size */</span></div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  printf(<span class="stringliteral">"Test Case 1..."</span>);</div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  <span class="keywordtype">int</span> arr[1000005]={0}; <span class="comment">/* array to store prime numbers */</span></div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <a class="code" href="../../d1/ded/group__misc.html#gac1a7a8e00eeb590511465c28fae16e54">prime</a>(arr);</div>
|
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  assert(<a class="code" href="../../d1/ded/group__misc.html#ga6f8e8c9d25b5891d57e588d80d75028a">count</a>(arr,size)==4);</div>
|
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  printf(<span class="stringliteral">"Passed\n"</span>);</div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span> }</div>
|
|
<div class="ttc" id="agroup__misc_html_ga6f8e8c9d25b5891d57e588d80d75028a"><div class="ttname"><a href="../../d1/ded/group__misc.html#ga6f8e8c9d25b5891d57e588d80d75028a">count</a></div><div class="ttdeci">int count(int *arr, const int size)</div><div class="ttdoc">Count func counts the number of prime numbers.</div><div class="ttdef"><b>Definition:</b> prime_seive.c:42</div></div>
|
|
<div class="ttc" id="agroup__misc_html_gac1a7a8e00eeb590511465c28fae16e54"><div class="ttname"><a href="../../d1/ded/group__misc.html#gac1a7a8e00eeb590511465c28fae16e54">prime</a></div><div class="ttdeci">void prime(int *p)</div><div class="ttdoc">Prime Sieve works in O(nlogn) time.</div><div class="ttdef"><b>Definition:</b> prime_seive.c:21</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="../../d1/ded/group__misc_gaa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="158" height="88"><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="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|