-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.cm
52 lines (46 loc) · 819 Bytes
/
example2.cm
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
48
49
50
51
/***********************************************
*
* A program to perform selection sort on a 10
* element array.
*
***********************************************/
int minloc ( int a[], int low, int high ) {
int i; int x; int k;
k = low;
x = a[ low ];
i = low + 1;
while( i < high ) { /* do swap */
if( a[ i ] < x ) {
x = a[ i ];
k = i;
}
i = i + 1;
}
return k;
}
void sort( int a[], int low, int high ) {
int i; int k; int t;
i = low;
while( i < high - 1 ) {
int t;
k = minloc( a, i, high );
t = a[ k ];
a[ k ] = a[ i ];
a[ i ] = t;
i = i + 1;
}
}
void main( void ) {
int i;
i = 0;
while( i < 10 ) {
read x[ i ];
i = i + 1;
}
sort( x, 0, 10 );
i = 0;
while( i < 10 ) {
write( x[ i ] );
i = i + 1;
}
}