home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume21 / cloops / part01 / sordid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-25  |  1.4 KB  |  63 lines

  1. /*
  2.  * This file is part of the Livermore Loops transliteration into C.
  3.  * Copyright (C) 1991 by Martin Fouts
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 1, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include "types.h"
  21.  
  22. Void sordid(i,w,v,n,kind)
  23. Int i[];
  24. Float w[];
  25. Float v[];
  26. Int n;
  27. Int kind;
  28. {
  29.   Int j, k, m;
  30.   Float x;
  31.   for (k = 0; k < n; k++) {
  32.     w[k] = v[k];
  33.     i[k] = k;
  34.   }
  35.   if (kind == 1) {
  36.     for (j = 0; j < n - 1; j++) {
  37.       m = j;
  38.       for (k = j + 1; k < n; k++)
  39.     if (w[k] < w[m]) m = k;
  40.       x = w[j];
  41.       k = i[j];
  42.       w[j] = w[m];
  43.       i[j] = i[m];
  44.       w[m] = x;
  45.       i[m] = k;
  46.     }
  47.     return;
  48.   } else {
  49.     for (j = 0; j < n - 1; j++) {
  50.       m = j;
  51.       for (k = j + 1; k < n; k++)
  52.     if (w[k] > w[m]) m = k;
  53.       x = w[j];
  54.       k = i[j];
  55.       w[j] = w[m];
  56.       i[j] = i[m];
  57.       w[m] = x;
  58.       i[m] = k;
  59.     }
  60.     return;
  61.   }
  62. }
  63.