1 /************************************** ********************
2 * Description *
3 * find the second big number from an array .*
4 * parameters *
5 * array is the array you want to look up; size is T -*
6 * He array's length; psec is used to store the seco -*
7 * nd big number .*
8 * return value *
9 * parameters invalid,-1 is returned; not find *
10 * second big number,-2 is returned; success, 0 is *
11 * returned .*
12 *************************************** *******************/
13 int find_second_big_number (const int array [], int size, int * psec)
14 {
15 int Max;
16 int second;
17 int I = 0;
18
19 if (null = array | null = psec | size <2)
20 {
21 return-1;
22}
23
24/* initialize Max and second */
25 For (I = 1; I <size; I ++)
26 {
27 if (array [0]! = Array [I])
28 {
29 If (array [0]> array [I])
30 {
31 max = array [0];
32 second = array [I];
33}
34 else
35 {
36 max = array [I];
37 second = array [0];
38}
39 break;
40}
41}
42
43 if (I = size)
44 {
45 return-2;
46}
47
48/* find the second big number */
49 for (; I <size; I ++)
50 {
51 if (max <array [I])
52 {
53 second = max;
54 max = array [I];
55}
56 else if (max> array [I] & Second <array [I])
57 {
58 second = array [I];
59}
60}
61
62 * psec = second;
63
64 return 0;
65}