Hi
i am facing some problem with qsort() function it work well if the last element of array is larger then the 2nd last element. But in case if last element of array is smaller then the 2nd last it will sort the whole array and remains the last as it is. For example
Code:
int group_id_local[max_j]={2,1,4,5};// it work fine, output should be {1,2,4,5}
//but if i have this one
int group_id_local[max_j]={2,1,4,3};// output should be {1,2,4,3}
/* COMPARE FUNCTION FOR USING QSORT()*/
int cmpfunc (const void* a, const void* b)
{
if (*(int *)a < *(int *)b) return -1;
if (*(int *)a > *(int *)b) return 1;
return 0;
}
qsort(group_id_local,max_j, sizeof(int), cmpfunc);
int j;
printf ("sorted Array:\n");
for (j=0; j<=max_j; j++){
printf ("%d\n ",group_id_local[j]);
}
Plz help me why it will not sort the last element?