• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

I cant for the life of me understand Qsort!!!

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
I have an array of class objects. The class has 3 elements. First is string and the second and third are ints. If I can just figure out how to get Qsort to work in 3 instances... one to sort the array alphabetically by the strings and the other two to sort it numerically by the int's, I can finally get this hellish chapter of my life behind me!!! Could someone please help?

mdsn and the code samples I'm finding online are way way over my head in complexity and far too short in documentation
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
An "array" of class elements? What kind of array? 'C' style ... ie. you manually allocate an array of pointers to the objects? Or an STL vector? If it's the latter (and it should be!), you shouldn't be using qsort.

In any case ... if you *have* to use primitive arrays and qsort ... ie., because your teacher told you to, then we need more information:

void qsort(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *));

What bit are you having trouble with?