Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdlib.h>
    void qsort( void *base,
                size_t num,
                size_t width,
                int (*compar)
                     ( const void *, const void *) );

Description:
    The qsort function sorts an array of num elements, which is pointed to
    by base, using a modified version of Sedgewick's Quicksort algorithm.
     Each element in the array is width bytes in size.  The comparison
    function pointed to by compar is called with two arguments that point to
    elements in the array.  The comparison function shall return an integer
    less than, equal to, or greater than zero if the first argument is less
    than, equal to, or greater than the second argument.

    The version of the Quicksort algorithm that is employed was proposed by
    John L.  Bentley and M.  Douglas McIlroy in a 1993 issue of "Software
    Practice and Engineering".

Returns:
    The qsort function returns no value.

Example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char *CharVect[] = { "last", "middle", "first" };

    int compare( const void *op1, const void *op2 )
      {
        const char **p1 = (const char **) op1;
        const char **p2 = (const char **) op2;
        return( strcmp( *p1, *p2 ) );
      }

    void main()
      {
        qsort( CharVect, sizeof(CharVect)/sizeof(char *),
              sizeof(char *), compare );
        printf( "%s %s %s\n",
                CharVect[0], CharVect[1], CharVect[2] );
      }

    produces the following:

    first last middle

Classification:
    ANSI

Systems:
    All, Netware

See Also:
    bsearch

See Also: bsearch

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson