
Sorting array of pointers to int
: I have a linked list of structures, of which one member is of type int. I have
: also created an array of pointers to each int member and have tried in vain to
: figure out how to use quicksort to sort this array so that I can then search
: on the sorted array (binary search) and pull out any match(es) from the linked
: list of structures.
: I can sort an array of ints without difficulty, but sorting the array of
: pointers to int has eluded me. Any suggestions?
The only change is in the comparison function, where you have to cast
back the arguments to type pointer to pointer to int, dereference to
get the related integers, and return a comparison of the results.
(I've assumed you're using the standard qsort() here; if it's your
own implementation, then rewrite the comparison function accordingly).
Will