[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions , Volume 2

qsort Subroutine


Sorts a table of data in place.


Standard C Library (libc.a)


#include <stdlib.h>

void qsort (BaseNumberOfElementsSizeComparisonPointer)
void * Base;
size_t NumberOfElements, Size;
int  (*ComparisonPointer)(const void*, const void*);


The qsort subroutine sorts a table of data in place. It uses the quicker-sort algorithm.


Base Points to the element at the base of the table.
NumberOfElements Specifies the number of elements in the table.
Size Specifies the size of each element.
ComparisonPointer Points to the comparison function, which is passed two parameters that point to the objects being compared. The qsort subroutine sorts the array in ascending order according to the comparison function.

Return Values

The comparison function compares its parameters and returns a value as follows:

Because the comparison function need not compare every byte, the elements can contain arbitrary data in addition to the values being compared.

Note: If two items are the same when compared, their order in the output of this subroutine is unpredictable.

The pointer to the base of the table should be of type pointer-to-element, and cast to type pointer-to-character.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The bsearch subroutine, lsearch subroutine.

Searching and Sorting Example Program, Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]