Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ qsort(3C) — A/UX 0.7

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sort(1)

bsearch(3C)

lsearch(3C)

string(3C)



     qsort(3C)                                               qsort(3C)



     NAME
          qsort - quicker sort

     SYNOPSIS
          void qsort ((char *)base, nel, width, compar)
          unsigned nel, width;
          int (*compar)( );

     DESCRIPTION
          qsort is an implementation of the quicker-sort algorithm.
          It sorts a table of data in place.

          base points to the element at the base of the table.  nel is
          the number of elements in the table.  width is the width of
          an element in bytes; sizeof (base) should be used.  compar
          is the name of the comparison function, which is called with
          two arguments that point to the elements being compared.
          The function must return an integer less than, equal to, or
          greater than zero according as the first argument is to be
          considered less than, equal to, or greater than the second.

     NOTES
          The pointer to the base of the table should be of type
          pointer-to-element, and cast to type pointer-to-character.
          The comparison function need not compare every byte, so
          arbitrary data may be contained in the elements in addition
          to the values being compared.  The order in the output of
          the two items which compare as equal is unpredictable.

     EXAMPLE
          struct entry {
                 char    *name;
                 int     flags;
          };

          main()
          {
                 struct entry hp[100];
                 int entcmp();
                 int i, count;

                 for (i = 0; i < (count = 100); i++) {
                         /* fill the structure with the name
                                and flags */
                         .
                         .
                         .
                 }
                 qsort( (char *) hp, count, sizeof (hp[0]), entcmp);
          }

          entcmp(ep,ep2)



     Page 1                                        (last mod. 1/14/87)





     qsort(3C)                                               qsort(3C)



          struct entry *ep, *ep2;
          {
                 return (strcmp(ep->name, ep2->name));
          }

          will sort a set of names with associated flags in ASCII
          order.

     SEE ALSO
          sort(1), bsearch(3C), lsearch(3C), string(3C).













































     Page 2                                        (last mod. 1/14/87)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026