Hi,
I am sorting an double array, using qsort()
#include<stdio.h>
#include<stdlib.h>
...
int compar( const void *arg1, const void *arg2 )
{
return ( * ( double **) arg1 >= * (double** ) arg2 );
}
....
int main(int argc,char *argv[]){
...
qsort(array, size_ct,sizeof(double),compar);
...
}
It turns out that the following array:
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.727436
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.727436
0.000000
0.000000
0.000000
0.000000
0.000000
0.727436
0.000000
0.000000
0.727436
0.000000
0.727436
0.727436
0.000000
0.000000
0.000000
0.000000
0.727436
0.000000
0.000000
is sorted as :
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.727436
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.727436
0.727436
0.727436
0.727436
0.727436
0.727436
This is not correct with a 0.727436 placed between 0.000000s. Can you point out why it is wrong? And is qsort() in C standard library and available in both Windows and Linux?
Thanks!