I'm trying to use the qsort() to sort an array of object pointers (PointP = Point*) attached is the compare function and the sorting, The problem is that nothing happens and sorting doesn't occur.
int compareByAngleP(const void* elem1,const void* elem2) {
PointP point1 = (PointP) elem1;
PointP point2 = (PointP) elem2;
if (abs(point1->getAngle() - point2->getAngle())>0.001)
{
return point1->getAngle() - point2->getAngle();
}
return point1->getY() - point2->getY();
}
void sortArrayP(PointP* array, int size) {
qsort(array,size, sizeof(PointP), compareByAngleP);
}
void*?arrayis indeed the base-address of a sequence ofPointP, then your params are not setup correctly in your comparator. You're missing one level of indirection.