Concept

How does the C standard library function qsort() work?

ComputerScienceOne / Examples

"The standard library also provides a generic sorting function, qsort(). Though the name suggests a Quick Sort implementation, it does not necessarily have to be (it was when the function was originally designed). Modern implementations of qsort() may implement alternatives such as Merge Sort or non-recursive hybrid Quick Sort algorithms. The prototype and parameters are similar to the search functions but do not include a key. The array is also not const indicating that it will be changed (which is the whole point of calling the function). The function will sort elements in ascending order according to the provided comparator function.\n\nvoid qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))\n\n• base – pointer an array of elements\n\n• nmemb – the size of the array (number of members)\n\n• size – the size (in bytes) of each element (use sizeof())\n\n• compar – a comparator function used to order elements"

Related Ideas

How does the C standard library function qsort() work? | ComputerScienceOne | Bifalgorithm | Bifalgorithm