qsort
The FSF.qsort function allows to sort an array of any type of
data using the QuickSort algorithm.
void WINAPI qsort( void *Base, size_t NElem, size_t Width, int (__cdecl *fcmp)(const void *, const void *) );
Parameters
Base
Start of target array.
NElem
Array size in elements.
Width
The size of each element in bytes.
fcmp
User-defined comparison function that must be declared with __cdecl - C-style
calling convention. This function takes two arguments - elem1 and
elem2. These arguments are the pointers to the array elements. fcmp
function must compare these elements and return an integer value:
*elem1 < *elem2 | - fcmp returns value < 0 |
*elem1 == *elem2 | - fcmp returns value == 0 |
*elem1 > *elem2 | - fcmp returns value > 0 |
Return value
None.
Remarks
- See the C/C++ run-time library reference for more information.
- If you need to pass user-defined data to the compare function, you should use the qsortex function instead.
- The sort implemented by the qsort and qsortex functions is not stable. In other words, the order for the elements that are equal according to the compare function is not defined. The order can change when the array is sorted repeatedly.
Example
See also: