std::qsort (3) - Linux Manuals
std::qsort: std::qsort
NAME
Synopsis
Defined in header <cstdlib>
void qsort( void *ptr, std::size_t count, std::size_t size, /*compare-pred*/* comp ); (1)
void qsort( void *ptr, std::size_t count, std::size_t size, /*c-compare-pred*/* comp );
extern "C++" using /*compare-pred*/ = int(const void*, const void*); // exposition-only (2)
extern "C" using /*c-compare-pred*/ = int(const void*, const void*); // exposition-only
Sorts the given array pointed to by ptr in ascending order. The array contains count elements of size bytes. Function pointed to by comp is used for object comparison.
If comp indicates two elements as equivalent, their order 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 - The signature of the comparison function should be equivalent to the following:
Return value
(none)
Notes
Despite the name, C++, C, and POSIX standards do not require this function to be implemented using quicksort or make any complexity or stability guarantees.
The type of the elements of the array must be a TrivialType, otherwise the behavior is undefined.
The two overloads provided by the C++ standard library are distinct because the types of the parameter comp are distinct (language_linkage is part of its type)
Example
The following code sorts an array of integers using qsort().
// Run this code
Output:
See also
bsearch (function)
sort (function template)
is_trivial checks if a type is trivial
(C++11)