I am trying to find out how (using a quicksort algorithm) to sort an struct array by 2 criterias. For example say I had a struct of:
struct employee{
char
int compare_employee (struct employee * a, struct employee * b) {
int diff = strcmp(a->gender, b->gender);
if (diff) // if gender different
return -diff; // sort descending, please double check this and reverse in case I am wrong
return a->id - b->id; // else sort by id
}
Will output a negative number if a < b, positive if a > b, zero if they are equal.
Use it eigther in your own quicksort or as a qsort comparator.