题目一:求数组的最大值和次大值
void select_max(const int*a, int size, int&nMax, int& nSecondMax)
{
nMax = a[0];
nSecondMax = a[0];
for (int i = 0; i < size; i++)
{
if (nMax < a[i])
{
nSecondMax = nMax;
nMax = a[i];
}
else if (nSecondMax < a[i])
{
nSecondMax = a[i];
}
}
}
题目二:求最大值和最小值
void select_max(const int*a, int size, int&nMax, int& nMin)
{
nMax = a[0];
nMin = a[0];
for (int i = 0; i < size; i++)
{
if (nMax < a[i])
{
nMax=a[i];
}
if (nMin > a[i])
{
nMin = a[i];
}
}
}