-

Changes

Jump to: navigation, search

Functions HI-TECH C QSORT

1,080 bytes added, 23:02, 31 July 2017
Created page with "<strong>QSORT</strong> ==SYNOPSIS== #include <stdlib.h> void qsort(void * base, size_t nel, size_t width, int (*func)()) ==DESCRIPTION <strong>Qsort</strong>() i..."
<strong>QSORT</strong>
==SYNOPSIS==

#include <stdlib.h>

void qsort(void * base, size_t nel,
size_t width, int (*func)())


==DESCRIPTION
<strong>Qsort</strong>() is an implementation of the quicksort algorithm. It sorts an array of nel items, each of length
width bytes, located contiguously in memory at base.
Func is a pointer to a function used by <strong>qsort</strong>() to compare items. It calls func with pointers to two items to
be compared. If the first item is considered to be
greater than, equal to or less than the second then
<strong>func</strong>() should return a value greater than zero, equal
to zero or less than zero respectively.

static short array[100];

#define SIZE sizeof array/sizeof array[0]
a_func(p1, p2)
short * p1, * p2;
{
return *p1 - *p2;
}

sort_em()
{
qsort(array, SIZE,
sizeof array[0], a_func);
}


This will sort the array into ascending values. Note
the use of sizeof to make the code independent of the
size of a short, or the number of elements in the
array.

Navigation menu