home *** CD-ROM | disk | FTP | other *** search
- /*
- * This file is part of the Livermore Loops transliteration into C.
- * Copyright (C) 1991 by Martin Fouts
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "types.h"
-
- Void sordid(i,w,v,n,kind)
- Int i[];
- Float w[];
- Float v[];
- Int n;
- Int kind;
- {
- Int j, k, m;
- Float x;
- for (k = 0; k < n; k++) {
- w[k] = v[k];
- i[k] = k;
- }
- if (kind == 1) {
- for (j = 0; j < n - 1; j++) {
- m = j;
- for (k = j + 1; k < n; k++)
- if (w[k] < w[m]) m = k;
- x = w[j];
- k = i[j];
- w[j] = w[m];
- i[j] = i[m];
- w[m] = x;
- i[m] = k;
- }
- return;
- } else {
- for (j = 0; j < n - 1; j++) {
- m = j;
- for (k = j + 1; k < n; k++)
- if (w[k] > w[m]) m = k;
- x = w[j];
- k = i[j];
- w[j] = w[m];
- i[j] = i[m];
- w[m] = x;
- i[m] = k;
- }
- return;
- }
- }
-