1 /*  timqsrt.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 /*
9     Time the sort of an array orreal numbers using quick-sort.
10 
11     Input parameter:  size= n -> array of n double precision numbers
12 */
13 #include <time.h>
14 #include "ccmath.h"
main(int na,char ** av)15 void main(int na,char **av)
16 { int i,f,n; double *x,**v;
17   unsigned int seed; clock_t st,en;
18   if(na!=2){ printf("para: size\n"); exit(1);}
19   n=atoi(*++av);
20   seed=(unsigned int)time(NULL); setnrml(seed);
21   printf("     Time Quick Sort\n");
22   printf("  %d points input\n",n);
23   x=(double *)calloc(n,sizeof(*x));
24   v=(double **)calloc(n,sizeof(x));
25   for(i=0; i<n ;) x[i++]=nrml();
26   st=clock();
27   for(i=0; i<n ;++i) v[i]=x+i;
28   qsrt(v,0,n-1,dubcmp);
29   en=clock();
30   for(i=1,f=0; i<n ;++i){
31     if(*v[i] < *v[i-1]){ f=1; break;}
32    }
33   if(f) printf("  sort failed\n");
34   printf(" time= %.3f sec.\n",(double)(en-st)/(double)CLOCKS_PER_SEC);
35 }
36