-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRankSortSequential.c
More file actions
38 lines (35 loc) · 1010 Bytes
/
RankSortSequential.c
File metadata and controls
38 lines (35 loc) · 1010 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
/* PROGRAM RankSortSequential */
#include <stdlib.h>
#define n 100
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;
for (i = 1; i <= n; i++)
PutinPlace(i); /* put values[i] in place */
for (i = 1; i <= n; i++) {
cout << final[i] << " ";
if (i % 10 == 0) cout << endl;
}
cout << endl;
}