G
Geoff
I have an application that maintains two arrays of transmitter and
receiver frequencies. The arrays are optionally sorted by user command
which invokes the following functions.
// globals
#define MAX_ELEMENTS 1000
double Tx[MAX_ELEMENTS + 1];
double Rx[MAX_ELEMENTS + 1];
int compare(const void *e1, const void *e2)
{
return (int)(* (double *)e1 - * (double *)e2);
}
void SortFreqs()
{
printf("Transmitters= %i ... ", Ttotal);
qsort (Tx, Ttotal, sizeof(double), compare);
printf("Receivers= %i ... ", Rtotal);
qsort (Rx, Rtotal, sizeof(double), compare);
}
The data is typically entered by hand to 4 decimal places and the
analysis of the data (intermodulation study) is done to
user-modifiable precision of 3 decimal places. The user could enter
data to greater precision but I don't think DBL_EPSILON will ever be a
factor. The terminal array element is always 0.0 and the total number
of elements is always <= 1000 and the sort excludes the terminal zero.
It seems qsort is perfectly adequate for this purpose. Comments?
receiver frequencies. The arrays are optionally sorted by user command
which invokes the following functions.
// globals
#define MAX_ELEMENTS 1000
double Tx[MAX_ELEMENTS + 1];
double Rx[MAX_ELEMENTS + 1];
int compare(const void *e1, const void *e2)
{
return (int)(* (double *)e1 - * (double *)e2);
}
void SortFreqs()
{
printf("Transmitters= %i ... ", Ttotal);
qsort (Tx, Ttotal, sizeof(double), compare);
printf("Receivers= %i ... ", Rtotal);
qsort (Rx, Rtotal, sizeof(double), compare);
}
The data is typically entered by hand to 4 decimal places and the
analysis of the data (intermodulation study) is done to
user-modifiable precision of 3 decimal places. The user could enter
data to greater precision but I don't think DBL_EPSILON will ever be a
factor. The terminal array element is always 0.0 and the total number
of elements is always <= 1000 and the sort excludes the terminal zero.
It seems qsort is perfectly adequate for this purpose. Comments?