template typename AnyType int size AnyType _min const AnyType r_array

 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
template <typename AnyType, int size>
AnyType _min(const AnyType (&r_array)[size])
{
AnyType min_val = r_array[0];
for(int i = 1;i < size;i++)
{
if(r_array[i] <= min_val)
{
min_val = r_array[i];
}
}
return min_val;
}
const int MAX_SIZE = 5;
int _tmain(int argc, _TCHAR* argv[])
{
int iA[MAX_SIZE];
int min_val = 0;
iA[0] = 54;
iA[1] = 28;
iA[2] = 7;
iA[3] = 754;
iA[4] = 2435;
min_val = _min(iA);
cout << min_val << endl;
getch();
return 0;
}