-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRankSortParallel.c
More file actions
39 lines (36 loc) · 1019 Bytes
/
RankSortParallel.c
File metadata and controls
39 lines (36 loc) · 1019 Bytes
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
/* PROGRAM RankSortParallel */
/* Figure 2.3 */
#include <stdlib.h>
#define n 10
int values[n+1], final[n+1];
int i;
void PutinPlace( int src ) {
int testval, j, rank;
testval = values[src];
j = src; /* j moves through the whole array */
rank = 1; /* position of the first number in the arrays */
do {
j = j % n + 1; /* j moves to the next circular position */
if (testval > values[j] ||
(testval == values[j] && src > j))
rank = rank + 1;
} while (j != src);
final[rank] = testval; /*put into position*/
}
main() {
for (i = 1; i <= n; i++)
/*values[i] = rand() % 100; *//* initialize values */
cin >> values[i]; /* if to initialize with input values */
for (i = 1; i <= n; i++) {
cout << values[i] << " ";
if (i % 10 == 0) cout << endl;
}
cout << endl;
forall i = 1 to n do
PutinPlace(i); /* put values[i] in place */
for (i = 1; i <= n; i++) {
cout << final[i] << " ";
if (i % 10 == 0) cout << endl;
}
cout << endl;
}