<< Previous | Next >> | |
|
int qsort( char * base, unsigned n, unsigned s, int (*cmp) () );
Description
- Quick sort with center pivot, stack control, and easy-to-change comparison method. This version sorts fixed-length data items. It is ideal for integers, longs, floats and packed string data without delimiters. Raw integers, longs, floats or strings may be sorted, however, the string sort is not efficient.
Parameters
- base
- Base address of the raw string data.
- n
- Number of blocks to sort.
- s
- Number of bytes in each block.
- cmp
- User-supplied compare routine for two block pointers,
p
andq
, that returns an int with the same rules used by Unixstrcmp(p,q)
:
- = 0: Blocks p and q are equal
< 0: p is less than q
> 0: p is greater than q
- Beware of using ordinary
strcmp()
--it requires a null at the end of each string.
Return value
0
if the operation is successful.Library
- SYS.LIB
Example - Sorts an array of integers.
Output from the above sample program:0. -90, 12
1. -2, 1
2. 1, 3
3. 3, -2
4. 7, 16
5. 9, 7
6. 10, 9
7. 12, 34
8. 16, -90
9. 34, 10
Dynamic C Functions | << Previous | Next >> | rabbit.com |