-
Notifications
You must be signed in to change notification settings - Fork 0
/
arraysort2D.c
49 lines (43 loc) · 1.55 KB
/
arraysort2D.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
44
45
46
47
/***********************************************************************************/
/* 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>
void arraysort2D(double **ID, int rows, int cols, int by, int incr){
int j, k, h;
double dtemp;
switch (incr) {
/*-------------------------------*/
case 1: /* If 'incr' is 1 (true) */
/*-------------------------------*/
for(j=rows-2; j>=0; j--){
for(k=0; k<=j; k++){
if(ID[k][by] > ID[k+1][by]){
for(h=0; h<cols; h++){
dtemp = ID[k][h];
ID[k][h] = ID[k+1][h];
ID[k+1][h] = dtemp;
}
}
}
}
break;
/*-------------------------------*/
default: /* If 'incr' is not 1 (false) */
/*-------------------------------*/
for(j=rows-2; j>=0; j--){
for(k=0; k<=j; k++){
if(ID[k][by] < ID[k+1][by]){
for(h=0; h<cols; h++){
dtemp = ID[k][h];
ID[k][h] = ID[k+1][h];
ID[k+1][h] = dtemp;
}
}
}
}
break;
}
}