2020-07-04 21:01:07 +03:00
<!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" / >
2020-08-26 19:14:44 +03:00
< meta name = "generator" content = "Doxygen 1.8.19" / >
2020-07-04 21:01:07 +03:00
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< title > Algorithms_in_C: Sorting algorithms< / 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 -->
2020-08-26 19:14:44 +03:00
<!-- Generated by Doxygen 1.8.19 -->
2020-07-04 21:01:07 +03:00
< 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');
/* @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('d5/d4c/group__sorting.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 = "#define-members" > Macros< / a > |
< a href = "#func-members" > Functions< / a > < / div >
< div class = "headertitle" >
< div class = "title" > Sorting algorithms< / div > < / div >
< / div > <!-- header -->
< div class = "contents" >
< table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "define-members" > < / a >
Macros< / h2 > < / td > < / tr >
< tr class = "memitem:ga4fdb8af29a07ac8f496e49a11bf9f1bd" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "ga4fdb8af29a07ac8f496e49a11bf9f1bd" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > (i, j)      beads[i * < a class = "el" href = "../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > + j]< / td > < / tr >
< tr class = "memdesc:ga4fdb8af29a07ac8f496e49a11bf9f1bd" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Create easy access of elements from a 2D matrix stored in memory as a 1D array. < br / > < / td > < / tr >
< tr class = "separator:ga4fdb8af29a07ac8f496e49a11bf9f1bd" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "func-members" > < / a >
Functions< / h2 > < / td > < / tr >
< tr class = "memitem:gad7ed8cc4603f500d610054680d28b971" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#gad7ed8cc4603f500d610054680d28b971" > display< / a > (const int *arr, int n)< / td > < / tr >
< tr class = "memdesc:gad7ed8cc4603f500d610054680d28b971" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Displays the array, passed to this method. < a href = "../../d5/d4c/group__sorting.html#gad7ed8cc4603f500d610054680d28b971" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:gad7ed8cc4603f500d610054680d28b971" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ga2fb01e00dedb437a42010f6309e7eba8" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#ga2fb01e00dedb437a42010f6309e7eba8" > bead_sort< / a > (int *a, size_t len)< / td > < / tr >
< tr class = "memdesc:ga2fb01e00dedb437a42010f6309e7eba8" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > This is where the sorting of the array takes place. < a href = "../../d5/d4c/group__sorting.html#ga2fb01e00dedb437a42010f6309e7eba8" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ga2fb01e00dedb437a42010f6309e7eba8" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-07-04 22:07:10 +03:00
< tr class = "memitem:ga4b9708d87be7a409eff20e5e7e8b43c8" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#ga4b9708d87be7a409eff20e5e7e8b43c8" > swap< / a > (int *a, int *b)< / td > < / tr >
< tr class = "memdesc:ga4b9708d87be7a409eff20e5e7e8b43c8" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Swap two integer variables. < a href = "../../d5/d4c/group__sorting.html#ga4b9708d87be7a409eff20e5e7e8b43c8" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ga4b9708d87be7a409eff20e5e7e8b43c8" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ga8dc3ec66cb3350313fdb34bfd1674729" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#ga8dc3ec66cb3350313fdb34bfd1674729" > merge< / a > (int *a, int l, int r, int n)< / td > < / tr >
< tr class = "memdesc:ga8dc3ec66cb3350313fdb34bfd1674729" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Perform merge of segments. < a href = "../../d5/d4c/group__sorting.html#ga8dc3ec66cb3350313fdb34bfd1674729" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ga8dc3ec66cb3350313fdb34bfd1674729" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:gab99b8a397bdd0bf2903d66c22ba4ba43" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#gab99b8a397bdd0bf2903d66c22ba4ba43" > merge_sort< / a > (int *a, int n, int l, int r)< / td > < / tr >
< tr class = "memdesc:gab99b8a397bdd0bf2903d66c22ba4ba43" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Merge sort algorithm implementation. < a href = "../../d5/d4c/group__sorting.html#gab99b8a397bdd0bf2903d66c22ba4ba43" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:gab99b8a397bdd0bf2903d66c22ba4ba43" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-07-04 21:01:07 +03:00
< tr class = "memitem:gaeccaf61ff47279384d1dba8d869d5c2f" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "gaeccaf61ff47279384d1dba8d869d5c2f" > < / a >
void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#gaeccaf61ff47279384d1dba8d869d5c2f" > show_data< / a > (int *arr, long len)< / td > < / tr >
< tr class = "memdesc:gaeccaf61ff47279384d1dba8d869d5c2f" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Helper function to print array values. < br / > < / td > < / tr >
< tr class = "separator:gaeccaf61ff47279384d1dba8d869d5c2f" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ga5bc16eaf3ffe6a6ab66780dd445904c0" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d5/d4c/group__sorting.html#ga5bc16eaf3ffe6a6ab66780dd445904c0" > shell_sort< / a > (int *array, long LEN)< / td > < / tr >
< tr class = "memdesc:ga5bc16eaf3ffe6a6ab66780dd445904c0" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Shell sort algorithm. < a href = "../../d5/d4c/group__sorting.html#ga5bc16eaf3ffe6a6ab66780dd445904c0" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ga5bc16eaf3ffe6a6ab66780dd445904c0" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
< h2 class = "groupheader" > Function Documentation< / h2 >
< a id = "ga2fb01e00dedb437a42010f6309e7eba8" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ga2fb01e00dedb437a42010f6309e7eba8" > ◆ < / a > < / span > bead_sort()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void bead_sort < / td >
< td > (< / td >
< td class = "paramtype" > int *  < / td >
< td class = "paramname" > < em > a< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > size_t  < / td >
< td class = "paramname" > < em > len< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > This is where the sorting of the array takes place. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > a< / td > < td > array to be sorted < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > len< / td > < td > Array Size < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00038" > < / a > < span class = "lineno" > 38< / span >   {< / div >
< div class = "line" > < a name = "l00039" > < / a > < span class = "lineno" > 39< / span >   < span class = "keywordtype" > int< / span > i, j, < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > , sum;< / div >
< div class = "line" > < a name = "l00040" > < / a > < span class = "lineno" > 40< / span >   < span class = "keywordtype" > unsigned< / span > < span class = "keywordtype" > char< / span > *beads;< / div >
< div class = "line" > < a name = "l00041" > < / a > < span class = "lineno" > 41< / span >   < / div >
< div class = "line" > < a name = "l00042" > < / a > < span class = "lineno" > 42< / span >   < span class = "keywordflow" > for< / span > (i = 1, < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > = a[0]; i < len; i++)< / div >
< div class = "line" > < a name = "l00043" > < / a > < span class = "lineno" > 43< / span >   < span class = "keywordflow" > if< / span > (a[i] > < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > )< / div >
< div class = "line" > < a name = "l00044" > < / a > < span class = "lineno" > 44< / span >   < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > = a[i];< / div >
< div class = "line" > < a name = "l00045" > < / a > < span class = "lineno" > 45< / span >   < / div >
< div class = "line" > < a name = "l00046" > < / a > < span class = "lineno" > 46< / span >   beads = calloc(1, < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > * len);< / 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 >   < span class = "comment" > /* mark the beads */< / span > < / div >
< div class = "line" > < a name = "l00049" > < / a > < span class = "lineno" > 49< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < len; i++)< / div >
< div class = "line" > < a name = "l00050" > < / a > < span class = "lineno" > 50< / span >   < span class = "keywordflow" > for< / span > (j = 0; j < a[i]; j++) < a class = "code" href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > (i, j) = 1;< / div >
< div class = "line" > < a name = "l00051" > < / a > < span class = "lineno" > 51< / span >   < / div >
< div class = "line" > < a name = "l00052" > < / a > < span class = "lineno" > 52< / span >   < span class = "keywordflow" > for< / span > (j = 0; j < < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > ; j++)< / div >
< div class = "line" > < a name = "l00053" > < / a > < span class = "lineno" > 53< / span >   {< / div >
< div class = "line" > < a name = "l00054" > < / a > < span class = "lineno" > 54< / span >   < span class = "comment" > /* count how many beads are on each post */< / span > < / div >
< div class = "line" > < a name = "l00055" > < / a > < span class = "lineno" > 55< / span >   < span class = "keywordflow" > for< / span > (sum = i = 0; i < len; i++)< / div >
< div class = "line" > < a name = "l00056" > < / a > < span class = "lineno" > 56< / span >   {< / div >
< div class = "line" > < a name = "l00057" > < / a > < span class = "lineno" > 57< / span >   sum += < a class = "code" href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > (i, j);< / div >
< div class = "line" > < a name = "l00058" > < / a > < span class = "lineno" > 58< / span >   < a class = "code" href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > (i, j) = 0;< / div >
< div class = "line" > < a name = "l00059" > < / a > < span class = "lineno" > 59< / span >   }< / div >
< div class = "line" > < a name = "l00060" > < / a > < span class = "lineno" > 60< / span >   < span class = "comment" > /* mark bottom sum beads */< / span > < / div >
< div class = "line" > < a name = "l00061" > < / a > < span class = "lineno" > 61< / span >   < span class = "keywordflow" > for< / span > (i = len - sum; i < len; i++) < a class = "code" href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > (i, j) = 1;< / div >
< div class = "line" > < a name = "l00062" > < / a > < span class = "lineno" > 62< / span >   }< / div >
< div class = "line" > < a name = "l00063" > < / a > < span class = "lineno" > 63< / span >   < / div >
< div class = "line" > < a name = "l00064" > < / a > < span class = "lineno" > 64< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < len; i++)< / div >
< div class = "line" > < a name = "l00065" > < / a > < span class = "lineno" > 65< / span >   {< / div >
< div class = "line" > < a name = "l00066" > < / a > < span class = "lineno" > 66< / span >   < span class = "keywordflow" > for< / span > (j = 0; j < < a class = "code" href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > & & < a class = "code" href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > (i, j); j++)< / div >
< div class = "line" > < a name = "l00067" > < / a > < span class = "lineno" > 67< / span >   ;< / div >
< div class = "line" > < a name = "l00068" > < / a > < span class = "lineno" > 68< / span >   a[i] = j;< / div >
< div class = "line" > < a name = "l00069" > < / a > < span class = "lineno" > 69< / span >   }< / div >
< div class = "line" > < a name = "l00070" > < / a > < span class = "lineno" > 70< / span >   free(beads);< / div >
< div class = "line" > < a name = "l00071" > < / a > < span class = "lineno" > 71< / span >   }< / div >
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "gad7ed8cc4603f500d610054680d28b971" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#gad7ed8cc4603f500d610054680d28b971" > ◆ < / a > < / span > display()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void display < / td >
< td > (< / td >
< td class = "paramtype" > const int *  < / td >
< td class = "paramname" > < em > arr< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / 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 > Displays the array, passed to this method. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > arr< / td > < td > array to display < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > n< / td > < td > number of elements in the array < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00024" > < / a > < span class = "lineno" > 24< / span >   {< / div >
< div class = "line" > < a name = "l00025" > < / a > < span class = "lineno" > 25< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < n; i++)< / div >
< div class = "line" > < a name = "l00026" > < / a > < span class = "lineno" > 26< / span >   {< / div >
< div class = "line" > < a name = "l00027" > < / a > < span class = "lineno" > 27< / span >   printf(< span class = "stringliteral" > " %d " < / span > , arr[i]);< / div >
< div class = "line" > < a name = "l00028" > < / a > < span class = "lineno" > 28< / span >   }< / 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 >   printf(< span class = "stringliteral" > " \n" < / span > );< / div >
< div class = "line" > < a name = "l00031" > < / a > < span class = "lineno" > 31< / span >   }< / div >
< / div > <!-- fragment -->
2020-07-04 22:07:10 +03:00
< / div >
< / div >
< a id = "ga8dc3ec66cb3350313fdb34bfd1674729" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ga8dc3ec66cb3350313fdb34bfd1674729" > ◆ < / a > < / span > merge()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void merge < / td >
< td > (< / td >
< td class = "paramtype" > int *  < / td >
< td class = "paramname" > < em > a< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > l< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > r< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / 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 > Perform merge of segments. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramname" > a< / td > < td > array to sort < / td > < / tr >
< tr > < td class = "paramname" > l< / td > < td > left index for merge < / td > < / tr >
< tr > < td class = "paramname" > r< / td > < td > right index for merge < / td > < / tr >
< tr > < td class = "paramname" > n< / td > < td > total number of elements in the array < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00034" > < / a > < span class = "lineno" > 34< / span >   {< / div >
< div class = "line" > < a name = "l00035" > < / a > < span class = "lineno" > 35< / span >   < span class = "keywordtype" > int< / span > *b = (< span class = "keywordtype" > int< / span > *)malloc(n * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > int< / span > )); < span class = "comment" > /* dynamic memory must be freed */< / span > < / div >
< div class = "line" > < a name = "l00036" > < / a > < span class = "lineno" > 36< / span >   < span class = "keywordtype" > int< / span > c = l;< / div >
< div class = "line" > < a name = "l00037" > < / a > < span class = "lineno" > 37< / span >   < span class = "keywordtype" > int< / span > p1, p2;< / div >
< div class = "line" > < a name = "l00038" > < / a > < span class = "lineno" > 38< / span >   p1 = l;< / div >
< div class = "line" > < a name = "l00039" > < / a > < span class = "lineno" > 39< / span >   p2 = ((l + r) / 2) + 1;< / div >
< div class = "line" > < a name = "l00040" > < / a > < span class = "lineno" > 40< / span >   < span class = "keywordflow" > while< / span > ((p1 < ((l + r) / 2) + 1) & & (p2 < r + 1))< / div >
< div class = "line" > < a name = "l00041" > < / a > < span class = "lineno" > 41< / span >   {< / div >
< div class = "line" > < a name = "l00042" > < / a > < span class = "lineno" > 42< / span >   < span class = "keywordflow" > if< / span > (a[p1] < = a[p2])< / div >
< div class = "line" > < a name = "l00043" > < / a > < span class = "lineno" > 43< / span >   {< / div >
< div class = "line" > < a name = "l00044" > < / a > < span class = "lineno" > 44< / span >   b[c++] = a[p1];< / div >
< div class = "line" > < a name = "l00045" > < / a > < span class = "lineno" > 45< / span >   p1++;< / div >
< div class = "line" > < a name = "l00046" > < / a > < span class = "lineno" > 46< / span >   }< / div >
< div class = "line" > < a name = "l00047" > < / a > < span class = "lineno" > 47< / span >   < span class = "keywordflow" > else< / 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 >   b[c++] = a[p2];< / div >
< div class = "line" > < a name = "l00050" > < / a > < span class = "lineno" > 50< / span >   p2++;< / div >
< div class = "line" > < a name = "l00051" > < / a > < span class = "lineno" > 51< / span >   }< / div >
< div class = "line" > < a name = "l00052" > < / a > < span class = "lineno" > 52< / span >   }< / div >
< div class = "line" > < a name = "l00053" > < / a > < span class = "lineno" > 53< / span >   < / div >
< div class = "line" > < a name = "l00054" > < / a > < span class = "lineno" > 54< / span >   < span class = "keywordflow" > if< / span > (p2 == r + 1)< / div >
< div class = "line" > < a name = "l00055" > < / a > < span class = "lineno" > 55< / span >   {< / div >
< div class = "line" > < a name = "l00056" > < / a > < span class = "lineno" > 56< / span >   < span class = "keywordflow" > while< / span > ((p1 < ((l + r) / 2) + 1))< / div >
< 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 >   b[c++] = a[p1];< / div >
< div class = "line" > < a name = "l00059" > < / a > < span class = "lineno" > 59< / span >   p1++;< / div >
< div class = "line" > < a name = "l00060" > < / a > < span class = "lineno" > 60< / span >   }< / div >
< div class = "line" > < a name = "l00061" > < / a > < span class = "lineno" > 61< / span >   }< / div >
< div class = "line" > < a name = "l00062" > < / a > < span class = "lineno" > 62< / span >   < span class = "keywordflow" > else< / span > < / div >
< div class = "line" > < a name = "l00063" > < / a > < span class = "lineno" > 63< / span >   {< / div >
< div class = "line" > < a name = "l00064" > < / a > < span class = "lineno" > 64< / span >   < span class = "keywordflow" > while< / span > ((p2 < r + 1))< / div >
< div class = "line" > < a name = "l00065" > < / a > < span class = "lineno" > 65< / span >   {< / div >
< div class = "line" > < a name = "l00066" > < / a > < span class = "lineno" > 66< / span >   b[c++] = a[p2];< / div >
< div class = "line" > < a name = "l00067" > < / a > < span class = "lineno" > 67< / span >   p2++;< / div >
< div class = "line" > < a name = "l00068" > < / a > < span class = "lineno" > 68< / span >   }< / div >
< div class = "line" > < a name = "l00069" > < / a > < span class = "lineno" > 69< / span >   }< / div >
< div class = "line" > < a name = "l00070" > < / a > < span class = "lineno" > 70< / span >   < / div >
< div class = "line" > < a name = "l00071" > < / a > < span class = "lineno" > 71< / span >   < span class = "keywordflow" > for< / span > (c = l; c < r - l + 1; c++) a[c] = b[c];< / div >
< div class = "line" > < a name = "l00072" > < / a > < span class = "lineno" > 72< / span >   < / div >
< div class = "line" > < a name = "l00073" > < / a > < span class = "lineno" > 73< / span >   free(b);< / div >
< div class = "line" > < a name = "l00074" > < / a > < span class = "lineno" > 74< / span >   }< / div >
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "gab99b8a397bdd0bf2903d66c22ba4ba43" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#gab99b8a397bdd0bf2903d66c22ba4ba43" > ◆ < / a > < / span > merge_sort()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void merge_sort < / td >
< td > (< / td >
< td class = "paramtype" > int *  < / td >
< td class = "paramname" > < em > a< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > n< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > l< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > r< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Merge sort algorithm implementation. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramname" > a< / td > < td > array to sort < / td > < / tr >
< tr > < td class = "paramname" > n< / td > < td > number of elements in the array < / td > < / tr >
< tr > < td class = "paramname" > l< / td > < td > index to sort from < / td > < / tr >
< tr > < td class = "paramname" > r< / td > < td > index to sort till < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00083" > < / a > < span class = "lineno" > 83< / span >   {< / div >
< div class = "line" > < a name = "l00084" > < / a > < span class = "lineno" > 84< / span >   < span class = "keywordflow" > if< / span > (r - l == 1)< / div >
< div class = "line" > < a name = "l00085" > < / a > < span class = "lineno" > 85< / span >   {< / div >
< div class = "line" > < a name = "l00086" > < / a > < span class = "lineno" > 86< / span >   < span class = "keywordflow" > if< / span > (a[l] > a[r])< / div >
< div class = "line" > < a name = "l00087" > < / a > < span class = "lineno" > 87< / span >   < a class = "code" href = "../../d5/d4c/group__sorting.html#ga4b9708d87be7a409eff20e5e7e8b43c8" > swap< / a > (& a[l], & a[r]);< / div >
< div class = "line" > < a name = "l00088" > < / a > < span class = "lineno" > 88< / span >   }< / div >
< div class = "line" > < a name = "l00089" > < / a > < span class = "lineno" > 89< / span >   < span class = "keywordflow" > else< / span > < span class = "keywordflow" > if< / span > (l != r)< / div >
< div class = "line" > < a name = "l00090" > < / a > < span class = "lineno" > 90< / span >   {< / div >
< div class = "line" > < a name = "l00091" > < / a > < span class = "lineno" > 91< / span >   < a class = "code" href = "../../d5/d4c/group__sorting.html#gab99b8a397bdd0bf2903d66c22ba4ba43" > merge_sort< / a > (a, n, l, (l + r) / 2);< / div >
< div class = "line" > < a name = "l00092" > < / a > < span class = "lineno" > 92< / span >   < a class = "code" href = "../../d5/d4c/group__sorting.html#gab99b8a397bdd0bf2903d66c22ba4ba43" > merge_sort< / a > (a, n, ((l + r) / 2) + 1, r);< / div >
< div class = "line" > < a name = "l00093" > < / a > < span class = "lineno" > 93< / span >   < a class = "code" href = "../../d5/d4c/group__sorting.html#ga8dc3ec66cb3350313fdb34bfd1674729" > merge< / a > (a, l, r, n);< / div >
< div class = "line" > < a name = "l00094" > < / a > < span class = "lineno" > 94< / span >   }< / div >
< div class = "line" > < a name = "l00095" > < / a > < span class = "lineno" > 95< / span >   < / div >
< div class = "line" > < a name = "l00096" > < / a > < span class = "lineno" > 96< / span >   < span class = "comment" > /* no change if l == r */< / span > < / div >
< div class = "line" > < a name = "l00097" > < / a > < span class = "lineno" > 97< / 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 = "../../d5/d4c/group__sorting_gab99b8a397bdd0bf2903d66c22ba4ba43_cgraph.svg" width = "204" height = "88" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
2020-07-04 21:01:07 +03:00
< / div >
< / div >
< a id = "ga5bc16eaf3ffe6a6ab66780dd445904c0" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ga5bc16eaf3ffe6a6ab66780dd445904c0" > ◆ < / a > < / span > shell_sort()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void shell_sort < / td >
< td > (< / td >
< td class = "paramtype" > int *  < / td >
< td class = "paramname" > < em > array< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > long  < / td >
< td class = "paramname" > < em > LEN< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Shell sort algorithm. < / p >
< p > < br / >
Optimized algorithm - takes half the time as other < / p > < dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > array< / td > < td > array to sort < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > LEN< / td > < td > length of the array < / td > < / tr >
< / table >
< / 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 = "keyword" > const< / span > < span class = "keywordtype" > int< / span > gaps[] = {701, 301, 132, 57, 23, 10, 4, 1};< / div >
< div class = "line" > < a name = "l00044" > < / a > < span class = "lineno" > 44< / span >   < span class = "keyword" > const< / span > < span class = "keywordtype" > int< / span > gap_len = 8;< / div >
< div class = "line" > < a name = "l00045" > < / a > < span class = "lineno" > 45< / span >   < span class = "keywordtype" > long< / span > i, j, g;< / div >
< div class = "line" > < a name = "l00046" > < / a > < span class = "lineno" > 46< / span >   < / div >
< div class = "line" > < a name = "l00047" > < / a > < span class = "lineno" > 47< / span >   < span class = "keywordflow" > for< / span > (g = 0; g < gap_len; g++)< / div >
< div class = "line" > < a name = "l00048" > < / a > < span class = "lineno" > 48< / span >   { < span class = "comment" > // for each gap< / span > < / div >
< div class = "line" > < a name = "l00049" > < / a > < span class = "lineno" > 49< / span >   < span class = "keywordtype" > int< / span > gap = gaps[g];< / div >
< div class = "line" > < a name = "l00050" > < / a > < span class = "lineno" > 50< / span >   < span class = "keywordflow" > for< / span > (i = gap; i < LEN; i++)< / div >
< div class = "line" > < a name = "l00051" > < / a > < span class = "lineno" > 51< / span >   { < span class = "comment" > // from gap position to the end< / span > < / div >
< div class = "line" > < a name = "l00052" > < / a > < span class = "lineno" > 52< / span >   < span class = "keywordtype" > int< / span > tmp = array[i];< / div >
< div class = "line" > < a name = "l00053" > < / a > < span class = "lineno" > 53< / span >   < / div >
< div class = "line" > < a name = "l00054" > < / a > < span class = "lineno" > 54< / span >   < span class = "keywordflow" > for< / span > (j = i; j > = gap & & (array[j - gap] - tmp) > 0; j -= gap)< / div >
< div class = "line" > < a name = "l00055" > < / a > < span class = "lineno" > 55< / span >   array[j] = array[j - gap];< / div >
< div class = "line" > < a name = "l00056" > < / a > < span class = "lineno" > 56< / span >   array[j] = tmp;< / div >
< 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 >   }< / div >
< div class = "line" > < a name = "l00059" > < / a > < span class = "lineno" > 59< / span >   < span class = "preprocessor" > #ifdef DEBUG< / span > < / div >
< div class = "line" > < a name = "l00060" > < / a > < span class = "lineno" > 60< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < LEN; i++) printf(< span class = "stringliteral" > " %s\t" < / span > , < a class = "code" href = "../../df/dea/structdata.html" > data< / a > [i]);< / div >
< div class = "line" > < a name = "l00061" > < / a > < span class = "lineno" > 61< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00062" > < / a > < span class = "lineno" > 62< / span >   }< / div >
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "ga4b9708d87be7a409eff20e5e7e8b43c8" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ga4b9708d87be7a409eff20e5e7e8b43c8" > ◆ < / a > < / span > swap()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void swap < / td >
< td > (< / td >
< td class = "paramtype" > int *  < / td >
< td class = "paramname" > < em > a< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int *  < / td >
< td class = "paramname" > < em > b< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-07-04 22:07:10 +03:00
< p > Swap two integer variables. < / p >
< p > Function to swap values of two integers.< / p >
2020-07-04 21:01:07 +03:00
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
2020-07-04 22:07:10 +03:00
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > a< / td > < td > pointer to first variable < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > b< / td > < td > pointer to second variable< / td > < / tr >
2020-07-04 21:01:07 +03:00
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > a< / td > < td > reference to first variable < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > b< / td > < td > reference to second variable < / td > < / tr >
< / table >
< / dd >
< / dl >
2020-07-04 22:07:10 +03:00
< div class = "fragment" > < div class = "line" > < a name = "l00018" > < / a > < span class = "lineno" > 18< / span >   {< / div >
< div class = "line" > < a name = "l00019" > < / a > < span class = "lineno" > 19< / span >   < span class = "keywordtype" > int< / span > t;< / div >
< div class = "line" > < a name = "l00020" > < / a > < span class = "lineno" > 20< / span >   t = *a;< / div >
< div class = "line" > < a name = "l00021" > < / a > < span class = "lineno" > 21< / span >   *a = *b;< / div >
< div class = "line" > < a name = "l00022" > < / a > < span class = "lineno" > 22< / span >   *b = t;< / div >
< div class = "line" > < a name = "l00023" > < / a > < span class = "lineno" > 23< / span >   }< / div >
2020-07-04 21:01:07 +03:00
< / div > <!-- fragment -->
< / div >
< / div >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
2020-07-04 22:07:10 +03:00
< div class = "ttc" id = "agroup__sorting_html_ga4b9708d87be7a409eff20e5e7e8b43c8" > < div class = "ttname" > < a href = "../../d5/d4c/group__sorting.html#ga4b9708d87be7a409eff20e5e7e8b43c8" > swap< / a > < / div > < div class = "ttdeci" > void swap(int *a, int *b)< / div > < div class = "ttdoc" > Swap two integer variables.< / div > < div class = "ttdef" > < b > Definition:< / b > merge_sort.c:17< / div > < / div >
2020-07-04 21:01:07 +03:00
< div class = "ttc" id = "astructdata_html" > < div class = "ttname" > < a href = "../../df/dea/structdata.html" > data< / a > < / div > < div class = "ttdef" > < b > Definition:< / b > prime_factoriziation.c:25< / div > < / div >
2020-07-04 22:07:10 +03:00
< div class = "ttc" id = "agroup__sorting_html_ga8dc3ec66cb3350313fdb34bfd1674729" > < div class = "ttname" > < a href = "../../d5/d4c/group__sorting.html#ga8dc3ec66cb3350313fdb34bfd1674729" > merge< / a > < / div > < div class = "ttdeci" > void merge(int *a, int l, int r, int n)< / div > < div class = "ttdoc" > Perform merge of segments.< / div > < div class = "ttdef" > < b > Definition:< / b > merge_sort.c:33< / div > < / div >
2020-07-04 21:01:07 +03:00
< div class = "ttc" id = "agroup__kohonen__2d_html_gaffe776513b24d84b39af8ab0930fef7f" > < div class = "ttname" > < a href = "../../d1/d6b/group__kohonen__2d.html#gaffe776513b24d84b39af8ab0930fef7f" > max< / a > < / div > < div class = "ttdeci" > #define max(a, b)< / div > < div class = "ttdoc" > shorthand for maximum value< / div > < div class = "ttdef" > < b > Definition:< / b > kohonen_som_topology.c:39< / div > < / div >
2020-07-04 22:07:10 +03:00
< div class = "ttc" id = "agroup__sorting_html_gab99b8a397bdd0bf2903d66c22ba4ba43" > < div class = "ttname" > < a href = "../../d5/d4c/group__sorting.html#gab99b8a397bdd0bf2903d66c22ba4ba43" > merge_sort< / a > < / div > < div class = "ttdeci" > void merge_sort(int *a, int n, int l, int r)< / div > < div class = "ttdoc" > Merge sort algorithm implementation.< / div > < div class = "ttdef" > < b > Definition:< / b > merge_sort.c:82< / div > < / div >
2020-07-04 21:01:07 +03:00
< div class = "ttc" id = "agroup__sorting_html_ga4fdb8af29a07ac8f496e49a11bf9f1bd" > < div class = "ttname" > < a href = "../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd" > BEAD< / a > < / div > < div class = "ttdeci" > #define BEAD(i, j)< / div > < div class = "ttdoc" > Create easy access of elements from a 2D matrix stored in memory as a 1D array.< / div > < div class = "ttdef" > < b > Definition:< / b > bead_sort.c:16< / div > < / div >
<!-- start footer part -->
< div id = "nav-path" class = "navpath" > <!-- id is needed for treeview function! -->
< ul >
2020-08-26 19:14:44 +03:00
< li class = "footer" > Generated by < a href = "http://www.doxygen.org/index.html" > < img class = "footer" src = "../../doxygen.svg" width = "104" height = "31" alt = "doxygen" / > < / a > 1.8.19 < / li >
2020-07-04 21:01:07 +03:00
< / ul >
< / div >
< / body >
< / html >