I need an efficient sort that doesn't have a callback, but is just as customizable as using qsort (). I want it to work as an iterator, where it continuously calls the sort API in a loop until it completes, doing the comparison in a loop, and not turning off the callback function. Thus, the user comparison is local to the calling function (and therefore has access to local variables, potentially more efficiently, etc.). I implemented this for inefficient sorting, but it needs to be efficient, so prefer quick derivative sorting.
Has anyone done something like this? I tried to do this for quick sorting, but trying to turn the algorithm from the inside damaged my brain too much.
Below is an example of use.
MyData array[5000], *firstP, *secondP;
Sorter sorter;
int result = sortInit (&sorter, array, 5000,
(void **)&firstP, (void **)&secondP, sizeof(MyData));
while (sortIteration (&sorter, result) == 0) {
result = firstP->value - secondP->value;
}
source
share