[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


qsort

Sort an array.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdlib.h>
void qsort(void *base,size_t nmemb,
  size_t size,
  int (*compare) (const void *, const void *))
Parameters:

Parameters for this facility are:

base  
void *  
A pointer to the array to be sorted  
nmemb  
size_t  
The number of elements  
size  
size_t  
The size of the elements  
compare  
void *  
A pointer to a comparison function  

Remarks:

The qsort() function sorts an array using the quicksort algorithm. It sorts the array without displacing it; the array occupies the same memory it had before the call to qsort().

The base argument is a pointer to the base of the array to be sorted.

The nmemb argument specifies the number of array elements to sort.

The size argument specifies the size of an array element.

The compare argument is a pointer to a programmer-supplied compare function. The function takes two pointers to different array elements and compares them based on the key. If the two elements are equal, compare must return a zero. The compare function must return a negative number if the first element is less than the second. Likewise, the function must return a positive number if the first argument is greater than the second.

See Also:

"bsearch"

For example of qsort() usage:
Refer to "Example of bsearch usage." .


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000