FastForward:
Fixed the qsort_longsamples() function. Sorry about that, it seems there was a bug with repeated numbers in the reference I used.
void qsort_longsamples(longsamples_t *sortedp, int first, int last) {
int pivot_index, i, j, k;
long pivot;
struct {
long data; /* data to be sorted */
int num; /* numbering of data */
} temp;
if (first < last) {
pivot = sortedp->data[first];
i = first+1;
j = last;
while (i <= j) {
while ((sortedp->data[i] <= pivot ) && (i <= last)) i++;
while ((sortedp->data[j] > pivot ) && (first < j)) j--;
if (i < j) {
temp.data = sortedp->data[i];
temp.num = sortedp->num[i];
sortedp->data[i] = sortedp->data[j];
sortedp->num[i] = sortedp->num[j];
sortedp->data[j] = temp.data;
sortedp->num[j] = temp.num;
}
}
temp.data = sortedp->data[j];
temp.num = sortedp->num[j];
sortedp->data[j] = sortedp->data[first];
sortedp->num[j] = sortedp->num[first];
sortedp->data[first] = temp.data;
sortedp->num[first] = temp.num;
qsort_longsamples(sortedp, first, j-1);
qsort_longsamples(sortedp, j+1, last);
}
}