home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 34.ddi / CSORTS.ZIP / LODCSWAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-02  |  799 b   |  55 lines

  1. /* Functions to sort X, Y, and Z arrays Z within Y within X
  2.  * Written by Ron Andrews 6-MAR-88 for demonstration purposes
  3.  */
  4.  
  5. extern int x[],y[],z[];
  6. static int xhold,yhold,zhold;
  7.  
  8. /* load the temporary variables
  9.  */
  10.  
  11. load(i)
  12. register i;
  13.     {
  14.     xhold = x[i];
  15.     yhold = y[i];
  16.     zhold = z[i];
  17.     }
  18.  
  19. /* check the variables against the temporary variable
  20.  */
  21.  
  22. check(i)
  23. register i;
  24.     {
  25.     if (xhold < x[i])
  26.         return(-1);
  27.     if (xhold > x[i])
  28.         return(1);
  29.     if (yhold < y[i])
  30.         return(-1);
  31.     if (yhold > y[i])
  32.         return(1);
  33.     if (zhold < z[i])
  34.         return(-1);
  35.     return(zhold > z[i]);
  36.     }
  37.  
  38. /* swap the variables
  39.  */
  40.  
  41. swap(i,j)
  42. register i,j;
  43.     {
  44.     static int t;
  45.     t = x[i];
  46.     x[i] = x[j];
  47.     x[j] = t;
  48.     t = y[i];
  49.     y[i] = y[j];
  50.     y[j] = t;
  51.     t = z[i];
  52.     z[i] = z[j];
  53.     z[j] = t;
  54.     }
  55.