mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
395 lines
25 KiB
HTML
395 lines
25 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.5"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: searching/exponential_search.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 id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">Algorithms_in_C<span id="projectnumber"> 1.0.0</span>
|
|
</div>
|
|
<div id="projectbrief">Set of algorithms implemented in C.</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.5 -->
|
|
<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" 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('da/d6c/exponential__search_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">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#define-members">Macros</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">exponential_search.c File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p><a href="https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/en/Search%20Algorithms/Exponential%20Search.md" target="_blank">Exponential Search</a>
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <assert.h></code><br />
|
|
<code>#include <inttypes.h></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for exponential_search.c:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../da/d31/exponential__search_8c__incl.svg" width="184" height="124"><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="define-members" name="define-members"></a>
|
|
Macros</h2></td></tr>
|
|
<tr class="memitem:aa5e9be47d76a4e1865914bcb7a2a7479"><td class="memItemLeft" align="right" valign="top"><a id="aa5e9be47d76a4e1865914bcb7a2a7479" name="aa5e9be47d76a4e1865914bcb7a2a7479"></a>
|
|
#define </td><td class="memItemRight" valign="bottom"><b>ELEMENT</b>   -10</td></tr>
|
|
<tr class="memdesc:aa5e9be47d76a4e1865914bcb7a2a7479"><td class="mdescLeft"> </td><td class="mdescRight">for assert for int64_t, uint16_t <br /></td></tr>
|
|
<tr class="separator:aa5e9be47d76a4e1865914bcb7a2a7479"><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:aae97ef76c065e91c188f1f8c8076869a"><td class="memItemLeft" align="right" valign="top">int64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d6c/exponential__search_8c.html#aae97ef76c065e91c188f1f8c8076869a">binary_search</a> (const int64_t *arr, const uint16_t l_index, const uint16_t r_index, const int64_t n)</td></tr>
|
|
<tr class="memdesc:aae97ef76c065e91c188f1f8c8076869a"><td class="mdescLeft"> </td><td class="mdescRight">used to perform the binary search over the given array <a href="../../da/d6c/exponential__search_8c.html#aae97ef76c065e91c188f1f8c8076869a">More...</a><br /></td></tr>
|
|
<tr class="separator:aae97ef76c065e91c188f1f8c8076869a"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a82d4de0907b9601a376febf50955bacd"><td class="memItemLeft" align="right" valign="top">int64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a> (const int64_t *arr, const uint16_t length, const int64_t n)</td></tr>
|
|
<tr class="memdesc:a82d4de0907b9601a376febf50955bacd"><td class="mdescLeft"> </td><td class="mdescRight">used to perform the exponential search over the given array <a href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">More...</a><br /></td></tr>
|
|
<tr class="separator:a82d4de0907b9601a376febf50955bacd"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d6c/exponential__search_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
|
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">used to run the self-test implementations <a href="../../da/d6c/exponential__search_8c.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
|
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d6c/exponential__search_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../da/d6c/exponential__search_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p ><a href="https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/en/Search%20Algorithms/Exponential%20Search.md" target="_blank">Exponential Search</a> </p>
|
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/faridevnz" target="_blank">Alessio Farinelli</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="aae97ef76c065e91c188f1f8c8076869a" name="aae97ef76c065e91c188f1f8c8076869a"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aae97ef76c065e91c188f1f8c8076869a">◆ </a></span>binary_search()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int64_t binary_search </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const int64_t * </td>
|
|
<td class="paramname"><em>arr</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const uint16_t </td>
|
|
<td class="paramname"><em>l_index</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const uint16_t </td>
|
|
<td class="paramname"><em>r_index</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const int64_t </td>
|
|
<td class="paramname"><em>n</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>used to perform the binary search over the given array </p>
|
|
<p >Function: binary_search.</p>
|
|
<p >algorithm that search the index of the given item</p>
|
|
<p >recursive function that search the given element in </p>
|
|
<h2><a class="anchor" id="autotoc_md80"></a>
|
|
the array using the <a href="https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/en/Search%20Algorithms/Binary%20Search.md" target="_blank" >Binary Search</a></h2>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">arr</td><td>array where search the element </td></tr>
|
|
<tr><td class="paramname">l_index</td><td>start index of the array (arr) to apply the algorithm </td></tr>
|
|
<tr><td class="paramname">r_index</td><td>end index of the array (arr) to apply the algorithm </td></tr>
|
|
<tr><td class="paramname">n</td><td>element to find in the array (arr)</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>the index of the element (n) in the array (arr) </dd>
|
|
<dd>
|
|
-1 if the n element wasn't found </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 56</span>{</div>
|
|
<div class="line"><span class="lineno"> 57</span> <span class="comment">// calculate the middle index of the array</span></div>
|
|
<div class="line"><span class="lineno"> 58</span> uint16_t middle_index = l_index + ( r_index - l_index ) / 2;</div>
|
|
<div class="line"><span class="lineno"> 59</span> <span class="comment">// base cases</span></div>
|
|
<div class="line"><span class="lineno"> 60</span> <span class="keywordflow">if</span> ( l_index > r_index ) { <span class="keywordflow">return</span> -1; }</div>
|
|
<div class="line"><span class="lineno"> 61</span> <span class="keywordflow">if</span> ( arr[middle_index] == n ) { <span class="keywordflow">return</span> middle_index; }</div>
|
|
<div class="line"><span class="lineno"> 62</span> <span class="comment">// recursion</span></div>
|
|
<div class="line"><span class="lineno"> 63</span> <span class="keywordflow">if</span> ( arr[middle_index] > n ) { <span class="keywordflow">return</span> <a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#aae97ef76c065e91c188f1f8c8076869a">binary_search</a>(arr, l_index, middle_index-1, n); } <span class="comment">// left</span></div>
|
|
<div class="line"><span class="lineno"> 64</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#aae97ef76c065e91c188f1f8c8076869a">binary_search</a>(arr, middle_index+1, r_index, n); <span class="comment">// right</span></div>
|
|
<div class="line"><span class="lineno"> 65</span>}</div>
|
|
<div class="ttc" id="aexponential__search_8c_html_aae97ef76c065e91c188f1f8c8076869a"><div class="ttname"><a href="../../da/d6c/exponential__search_8c.html#aae97ef76c065e91c188f1f8c8076869a">binary_search</a></div><div class="ttdeci">int64_t binary_search(const int64_t *arr, const uint16_t l_index, const uint16_t r_index, const int64_t n)</div><div class="ttdoc">used to perform the binary search over the given array</div><div class="ttdef"><b>Definition:</b> exponential_search.c:55</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="../../da/d6c/exponential__search_8c_aae97ef76c065e91c188f1f8c8076869a_cgraph.svg" width="114" height="60"><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="a82d4de0907b9601a376febf50955bacd" name="a82d4de0907b9601a376febf50955bacd"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a82d4de0907b9601a376febf50955bacd">◆ </a></span>exponential_search()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int64_t exponential_search </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const int64_t * </td>
|
|
<td class="paramname"><em>arr</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const uint16_t </td>
|
|
<td class="paramname"><em>length</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const int64_t </td>
|
|
<td class="paramname"><em>n</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>used to perform the exponential search over the given array </p>
|
|
<p >Function: exponential_search.</p>
|
|
<p >algorithm that search the index of the given item</p>
|
|
<p >recursive function that take an array and quickly find the range </p>
|
|
<h2><a class="anchor" id="autotoc_md79"></a>
|
|
where to apply the binary search algorithm to find the given element</h2>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">arr</td><td>array where search the element </td></tr>
|
|
<tr><td class="paramname">length</td><td>the total length of the given array (arr) </td></tr>
|
|
<tr><td class="paramname">n</td><td>element to find in the array (arr)</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>the index of the element (n) in the array (arr) </dd>
|
|
<dd>
|
|
-1 if the element wasn't found </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 29</span>{</div>
|
|
<div class="line"><span class="lineno"> 30</span> <span class="keywordflow">if</span> ( length == 0 ) { <span class="keywordflow">return</span> -1; }</div>
|
|
<div class="line"><span class="lineno"> 31</span> <span class="comment">// find the upperbound</span></div>
|
|
<div class="line"><span class="lineno"> 32</span> uint32_t upper_bound = 1;</div>
|
|
<div class="line"><span class="lineno"> 33</span> <span class="keywordflow">while</span> ( upper_bound <= length && arr[upper_bound] < n ) { upper_bound = upper_bound * 2; }</div>
|
|
<div class="line"><span class="lineno"> 34</span> <span class="comment">// calculate the range ( between lower_boud and upper_bound )</span></div>
|
|
<div class="line"><span class="lineno"> 35</span> uint16_t lower_bound = upper_bound/2;</div>
|
|
<div class="line"><span class="lineno"> 36</span> <span class="keywordflow">if</span> ( upper_bound > length ) { upper_bound = length; }</div>
|
|
<div class="line"><span class="lineno"> 37</span> <span class="comment">// apply the binary search in the range</span></div>
|
|
<div class="line"><span class="lineno"> 38</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#aae97ef76c065e91c188f1f8c8076869a">binary_search</a>(arr, lower_bound, upper_bound, n);</div>
|
|
<div class="line"><span class="lineno"> 39</span>}</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="../../da/d6c/exponential__search_8c_a82d4de0907b9601a376febf50955bacd_cgraph.svg" width="296" height="60"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Main function. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 72</span>{</div>
|
|
<div class="line"><span class="lineno"> 73</span> <a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
|
<div class="line"><span class="lineno"> 74</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><span class="lineno"> 75</span>}</div>
|
|
<div class="ttc" id="aexponential__search_8c_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../da/d6c/exponential__search_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">used to run the self-test implementations</div><div class="ttdef"><b>Definition:</b> exponential_search.c:81</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="../../da/d6c/exponential__search_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="487" height="60"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">◆ </a></span>test()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">static void test </td>
|
|
<td>(</td>
|
|
<td class="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>used to run the self-test implementations </p>
|
|
<p >Self-test implementations.</p>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 82</span>{</div>
|
|
<div class="line"><span class="lineno"> 83</span> <span class="comment">// empty array</span></div>
|
|
<div class="line"><span class="lineno"> 84</span> int64_t arr_empty[] = {};</div>
|
|
<div class="line"><span class="lineno"> 85</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_empty, 0, 10) == -1);</div>
|
|
<div class="line"><span class="lineno"> 86</span> <span class="comment">// elent not found</span></div>
|
|
<div class="line"><span class="lineno"> 87</span> int64_t arr_found[] = {1, 2, 3};</div>
|
|
<div class="line"><span class="lineno"> 88</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_found, 3, 10) == -1);</div>
|
|
<div class="line"><span class="lineno"> 89</span> <span class="comment">// element found in an array of length 1</span></div>
|
|
<div class="line"><span class="lineno"> 90</span> int64_t arr_one[] = {1};</div>
|
|
<div class="line"><span class="lineno"> 91</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_found, 1, 1) == 0);</div>
|
|
<div class="line"><span class="lineno"> 92</span> <span class="comment">// find the first element in an array of length 2</span></div>
|
|
<div class="line"><span class="lineno"> 93</span> int64_t arr_first_2[] = {1, 2};</div>
|
|
<div class="line"><span class="lineno"> 94</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_first_2, 2, 1) == 0);</div>
|
|
<div class="line"><span class="lineno"> 95</span> <span class="comment">// find the last element in an array of length 2</span></div>
|
|
<div class="line"><span class="lineno"> 96</span> int64_t arr_last_2[] = {1, 2};</div>
|
|
<div class="line"><span class="lineno"> 97</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_last_2, 2, 2) == 1);</div>
|
|
<div class="line"><span class="lineno"> 98</span> <span class="comment">// find the first element in an array of length n</span></div>
|
|
<div class="line"><span class="lineno"> 99</span> int64_t arr_first_n[] = {-1, 2, 4, 6, 8};</div>
|
|
<div class="line"><span class="lineno"> 100</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_first_n, 5, -1) == 0);</div>
|
|
<div class="line"><span class="lineno"> 101</span> <span class="comment">// find the last element in an array of length n</span></div>
|
|
<div class="line"><span class="lineno"> 102</span> int64_t arr_last_n[] = {-1, 2, 4, 6, 8};</div>
|
|
<div class="line"><span class="lineno"> 103</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_last_n, 5, 8) == 4);</div>
|
|
<div class="line"><span class="lineno"> 104</span> <span class="comment">// find an element in an array of length n</span></div>
|
|
<div class="line"><span class="lineno"> 105</span> int64_t arr_middle[] = {-1, 2, 4, 6, 8};</div>
|
|
<div class="line"><span class="lineno"> 106</span> assert(<a class="code hl_function" href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a>(arr_middle, 5, 6) == 3);</div>
|
|
<div class="line"><span class="lineno"> 107</span>}</div>
|
|
<div class="ttc" id="aexponential__search_8c_html_a82d4de0907b9601a376febf50955bacd"><div class="ttname"><a href="../../da/d6c/exponential__search_8c.html#a82d4de0907b9601a376febf50955bacd">exponential_search</a></div><div class="ttdeci">int64_t exponential_search(const int64_t *arr, const uint16_t length, const int64_t n)</div><div class="ttdoc">used to perform the exponential search over the given array</div><div class="ttdef"><b>Definition:</b> exponential_search.c:28</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="../../da/d6c/exponential__search_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="388" height="60"><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_da574daf9ce9c05b45556bdc871ed1e3.html">searching</a></li><li class="navelem"><a class="el" href="../../da/d6c/exponential__search_8c.html">exponential_search.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.5 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|