If I have an array like this:
2, 4, 6, 0, 0, 0, 0, 0, 0
- Is there a way I can use qsort by sorting just the first 3 elements, and leaving the rest untouched?
- Would
qsort(arrNumbers, 3, sizeof(int), compare)do the job? - Does specifying the number of elements lower than the full array cause only that number of elements to become sorted?
EDIT: My compare function is:
int comp(const int * a, const int * b)
if(a==b)
{
return 0;
}
else
{
if(a<b)
{
return -1;
}
else
{
return 1;
}
}
Does it seem right?