1 # include <stdio. h>
2 # include <stdlib. h>
3 # define LEN 10
4
5 int main ()
6 {
7 // min records the location of the minimum value.
8 int I, j, tmp, min, array [LEN];
9
10 // input data
11 printf ("please input members :");
12 for (I = 0; I <LEN; I ++)
13 scanf ("% d", & array [I]);
14
15 // output original data
16 for (I = 0; I <LEN; I ++)
17 printf ("% d", array [I]);
18 printf ("\ n ");
19
20 // One-Way Bubble sorting.
21/* for (I = 0; I <LEN-1; I ++)
22 for (j = I + 1; j <LEN; j ++)
23 {
24 if (array [I]> array [j])
25 {
26 tmp = array [j];
27 array [j] = array [I];
28 array [I] = tmp;
29}
30 }*/
31
32 // 100 Classic instances. If there is a large amount of data, this is more cost-effective.
33 for (I = 0; I <LEN-1; I ++)
34 {
35 min = I;
36 for (j = I + 1; j <LEN; j ++)
37 {
38 if (array [min]> array [j])
39 {
40 min = j;
41}
42}
43
44 if (I = min)
45 continue;
46
47 tmp = array [min];
48 array [min] = array [I];
49 array [I] = tmp;
50
51}
52
53 // output result.
54 printf ("\ nresult is: \ n ");
55 for (I = 0; I <LEN; I ++)
56 printf ("% d", array [I]);
57 printf ("\ n ");
58
59 // printf ("Hello world! \ N ");
60 return 0;
61}
From zhengmian