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

Technical Reference: Base Operating System and Extensions, Volume 2

qsort Subroutine

Purpose

Sorts a table of data in place.

Library

Standard C Library (libc.a)

Syntax

#include <stdlib.h>


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

Description

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

Parameters

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.

Related Information

The bsearch subroutine, lsearch subroutine.

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

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