"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/sort/qsrt.c" (16 Oct 2000, 773 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 "qsrt.c" see the Fossies "Dox" file reference documentation.

    1 /*  qsrt.c    CCMATH mathematics library source code.
    2  *
    3  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
    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 void qsrt(void **v,int i,int j,int (*comp)())
   10 { int up=j,lw=i; char *tmp,*pa;
   11   if(i>=j) return;
   12   --i; pa=v[up];
   13   while(i<j){
   14      for(++i; (*comp)(v[i],pa)<0 ;++i);
   15      for(--j; j>i && (*comp)(v[j],pa)>0 ;--j);
   16      if(i<j) Swap(v[i],v[j]);
   17     }
   18   Swap(v[i],v[up]);
   19   if(i-lw>up-i){ qsrt(v,i+1,up,comp); qsrt(v,lw,i-1,comp);}
   20   else{ qsrt(v,lw,i-1,comp); qsrt(v,i+1,up,comp);}
   21 }