home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / tst_sort.c < prev    next >
C/C++ Source or Header  |  1985-08-29  |  384b  |  22 lines

  1. /* tst_sort - returns YES if array a is sorted
  2.  * specialized "short" version
  3.  */
  4. #include "local.h"
  5. bool tst_sort(a, n)
  6.     short a[];
  7.     index_t n;
  8.     {
  9.     index_t i;
  10.  
  11.     if (n <= 0)
  12.         return (NO);
  13.     for (i = 1; i < n; ++i)
  14.         {
  15.         /* a[0:i-1] => sorted */
  16.         if (a[i] < a[i-1])        /* compare adjacent elements */
  17.             return (NO);
  18.         }
  19.     /* a[0:n-1] => sorted */
  20.     return (YES);
  21.     }
  22.