I have been looking through my c book trying to find a built in sorting function but... I can't seem to find one. I know they are their. Can someone tell me of one that I can use to sort a linked list...
Printable View
I have been looking through my c book trying to find a built in sorting function but... I can't seem to find one. I know they are their. Can someone tell me of one that I can use to sort a linked list...
Sort a linked list? Use qsort. You must define and write the compare function that goes into it, tho. Otherwise, write your own. Qsort will also sort strings, numbers, etc, again, provided you supply the compare function...
What headers do I have to call and what is the qsort usage... qsort(?)
stdlib.h
void qsort( const void* pBase, size_t cntObjects, size_t
sizeObject, _pfunccmp_t pfuncCmp);
maybe like :
int array[5] = {8}, {3}, {7}, {9}, {2};
qsort(array, 5, sizeof(int), myCompareFunc(??array??) );
Not sure just how to define that...hmmm...it's a start tho.
It'd actually be like:
qsort( array, 5, sizeof(int), myCompareFunction );
When you just use the name of a function, by itself, you are effectivly passing a pointer to the function. So the above should be correct. I say _should_ because I've never had need to actually use qsort.
Quzah.