Answers for "qsort compare function"

C
2

qsort in c

#include <stdlib.h>
int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}

int main () {
//n is number of elements in arr(size f that arr)
   qsort(arr, n, sizeof(int), cmpfunc);
   }
Posted by: Guest on August-13-2020
0

qsort compare function return type

int comparator(const void* p1, const void* p2);
Return value meaning
<0 The element pointed by p1 goes before the element pointed by p2
0  The element pointed by p1 is equivalent to the element pointed by p2
>0 The element pointed by p1 goes after the element pointed by p2

Source: http://www.cplusplus.com/reference/cstdlib/qsort/
Posted by: Guest on July-26-2021

Code answers related to "C"

Browse Popular Code Answers by Language