Hi,
The wonderful thing about SORTING is you don't really have to sort the elements. You really only need to sort the indexes.
The reason QSORT needs to know the size of the elements is because it 'SWAPS' the elements in the array.
However, there is no reason you need to pass in the real elements. You could pass in an array of indexes or pointers to the elements and sort the indexes.
something like
cmp(void *a, void *b )
{
elem *ma = (elem *)a;
elem *mb = (elem *)b;
return ( ma->data - mb->data )
}
then you create an array of pointers to your elements
I assume you aren't using an array for your list since they are different sizes, a linked list was the next assumption.
curr = head;
x = 0;
while ( curr != NULL )
{
ray[x] = curr;
curr = curr->next;
x ++;
}
qsort(ray,x,sizeof(elem *),cmp);
Then when you come back you don't access them through the linked list anymore but through the array.
for ( y = 0 ; y < x ; y ++ )
{
printf("%d\n",ray[x]->elem );
}