qsort()

perform quick sort 

Function


SYNOPSIS

#include <stdlib.h>

void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *), const void *));


DESCRIPTION

The qsort() function sorts an array of nmemb objects, the initial element of which is pointed to by base. The size of each object in bytes is specified by size. The contents of the array are sorted in ascending order according to a comparison function. The compar argument is a pointer to the comparison function, which is called with two arguments that point to the elements being compared. The function must return an integer less than, equal to, or greater than 0, if the first argument is considered respectively less than, equal to, or greater than the second. If two members compare as equal, their order in the sorted array is unspecified.

The qsort() function is an implementation of C.A.R. Hoare's quicksort algorithm, a variant of partition-exchange sorting. The algorithm is taken from Algorithm Q in D.E. Knuth's Sorting and Searching. It has O(n log n) average performance; this implementation uses median selection to avoid the O(n**2) worst-case performance of quicksort. The qsort() algorithm is not a stable sort.


PARAMETERS

base 

Points to the memory to be sorted.

nmemb 

Is the number of objects in memory.

size 

Is the size of each object in memory.

compar 

Is the sorting function.


RETURN VALUES

None.


CONFORMANCE

ANSI/ISO 9899-1990.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
heapsort(), mergesort(), radixsort(), sradixsort()


PTC MKS Toolkit 10.4 Documentation Build 39.