# MATH_QSort

## Syntax

      #include <nitro/math/qsort.h>

      void MATH_QSort( void *head,
                          u32   num,
                          u32 width,
                          MATHCompareFunc comp,
                          void *stackBuf );

## Arguments

head | Pointer to the data to sort.
num | The number of pieces of data to sort.
width | The size of each piece of data.
comp | Comparison function for the elements in the array.
stackBuf | Provides a buffer to be used internally. You can obtain the required buffer size with the `MATH_QSortStackSize` function. If this argument is NULL, memory will be allocated from the stack. Be alert to the possiblity of stack overflow.

## Return Values

None.

## Description

This function performs a quicksort.
The function does not use a recursive call. Instead, the `stackBuf` argument must be used to provide a work area for the sort.
If the work area is provided by NULL, the stack will be used for the sort. Be aware of the possiblity of stack overflow.
The required size of the work area is `(Log2(num)+1)*8` bytes. This value can be obtained with the `MATH_QSortStackSize` function.

## See Also

`MATH_QSortStackSize, MATHCompareFunc`

## Revision History

2005/04/12 Initial version.

CONFIDENTIAL