-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectorrank.c
45 lines (34 loc) · 1007 Bytes
/
vectorrank.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/***********************************************************************************/
/* Program: arraysort2D.c
By: Brad Duthie
Description: Sorts a 2D array by the value of a column element.
Compile: gcc randpois.c -ansi -Wall -pedantic */
/***********************************************************************************/
#include <stdio.h>
#include "array.h"
void vectorrank(double *vec, double **Rank, int xlen){
int i, j;
double *r, m, n;
MAKE_1ARRAY(r,xlen*xlen);
for(i=0; i<(xlen*xlen); i++){
r[i] = 0;
for(j=0; j<(xlen*xlen); j++){
if(vec[i] > vec[j]){
r[i]++;
}
}
}
m = 0.0; /*row */
n = 0.0; /* column */
for(i=0; i<(xlen*xlen); i++){
Rank[i][0] = m;
Rank[i][1] = n;
Rank[i][2] = r[i];
m++;
if(m==xlen){
n++;
m = 0;
}
}
FREE_1ARRAY(r);
}