## "Fossies" - the Fresh Open Source Software Archive

### Member "ccmath-2.2.1/sort/hsort.c" (16 Oct 2000, 836 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "hsort.c" see the Fossies "Dox" file reference documentation.

```    1 /*  hsort.c    CCMATH mathematics library source code.
2  *
4  *  This code may be redistributed under the terms of the GNU library
5  *  public license (LGPL). ( See the lgpl.license file for details.)
6  * ------------------------------------------------------------------------
7  */
8 #define Swap(x,y) (tmp=(x),(x)=(y),(y)=tmp)
9 static void rheap(void **v,int k,int n,int (*comp)());
10 void hsort(void **v,int n,int (*comp)())
11 hlOpen(11,1);{ int k; char *tmp;
12   for(k=n/2-1; k>=0 ;) rheap(v,k--,n,comp);
13   for(--n; n>0 ;)hlOpen(13,2);{ Swap(v[0],v[n]); rheap(v,0,n--,comp);hlClose(2, 13);}
14 hlClose(1, 14);}
15 static void rheap(void **v,int k,int n,int (*comp)())
16 hlOpen(16,1);{ int m=n-1,j; char *tmp;
17   for(j=2*k+1; j<n ;k=j,j=2*k+1)hlOpen(17,2);{
18     if(j<m && (*comp)(v[j+1],v[j])>0) ++j;
19     if((*comp)(v[j],v[k])>0) Swap(v[k],v[j]);
20     else break;
21    hlClose(4, 21);}
22 hlClose(3, 22);}
```