Using Quick Sort in C to sort in reverse direction (descending)?

前端 未结 3 800
温柔的废话
温柔的废话 2021-01-14 08:08

To sort I call qsort(myArray,100,sizeof(int), comp)

int comp(const int * a, const int * b)
if(a==b)
{
    return 0;
}
else
{
    if(a

        
3条回答
  •  一向
    一向 (楼主)
    2021-01-14 08:50

    Your comparator is broken. You are comparing the pointer values rather than the values being pointed to. Add the * dereference operator to the a and b comparisons and it should work.

提交回复
热议问题