So, I am using qsort in my C program from C library. It works as expected so I decided to play around with comparators.
Comparator 1 (I use this):
int compare (const void * a, const void * b)
{
if (*(double*)a > *(double*)b) return 1;
else if (*(double*)a < *(double*)b) return -1;
else return 0;
}
Comparator 2:
int comp (const void *a, const void *b)
{
const double *ia = (const double *)a; // casting pointer types
const double *ib = (const double *)b;
return *ia - *ib;
}
The first one works as I want to. The second one is supposed to do the same the first one. I would like to use the second because the program runs a bit faster, but the thing it that it doesn't really sort anything!
I am pretty sure that I have used comparator #2 on smaller arrays and it worked. Unless I am missing something there.