(en.cppreference.com) qsort, qsorts - cppreference.com
ROAM_REFS: https://en.cppreference.com/w/c/algorithm/qsort
- qsort, qsorts
Defined in header
<stdlib.h>void qsort( void* ptr, [[http://en.cppreference.com/w/c/types/size_t][size_t]] count, [[http://en.cppreference.com/w/c/types/size_t][size_t]] size,
int (*comp)(const void*, const void*) );
errno_t qsort_s( void* ptr, rsize_t count, rsize_t size,
int (*comp)(const void*, const void*, void*),
void* context );
- Sorts the given array pointed to by
ptrin ascending order. The array containscountelements ofsizebytes. Function pointed to bycompis used for object comparison.Same as (1), except that the additional context parameter context is passed to comp and that the following errors are detected at runtime and call the currently installed constraint handler function:
countorsizeis greater than RSIZEMAX ptrorcompis a null pointer (unlesscountis zero)As with all bounds-checked functions,
qsort_sis only guaranteed to be available if__STDC_LIB_EXT1__is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT1__to the integer constant 1 before including<stdlib.h>.If comp indicates two elements as equivalent, their order in the resulting sorted array is unspecified.
* Parameters
ptr - pointer to the array to sort count - number of elements in the array size - size of each element in the array in bytes comp - comparison function which returns a negative integer value if the first argument is less than the second, a positive integer value if the first argument is greater than the second and zero if the arguments are equivalent. The signature of the comparison function should be equivalent to the following:
The function must not modify the objects passed to it and must return consistent results when called for the same objects, regardless of their positions in the array. context - additional information (e.g., collating sequence), passed to
compas the third argument* Return value
- (none)
- zero on success, non-zero if a runtime constraints violation was detected