using
System;
public class SecMax
... {
//record the second max number
private static int secMax = Int32.MinValue;
//does the list has second max number
private static bool HasSecMax(int[] list)
...{
int max = list[0];
//get the max number
for(int i = 1;i < list.Length;i++)
...{
if(list[i] > max)
...{
max = list[i];
}
}
bool isFound = false;
//get the second max number
for(int j = 0;j < list.Length;j++)
...{
if((list[j] < max) && (list[j] > secMax))
...{
secMax = list[j];
isFound = true;
}
}
return isFound;
}
public static void Main()
...{
int[] list = new int[]...{1,2,3,4,5,6,7};
if(HasSecMax(list))
...{
Console.WriteLine("The SecMax number is:" + secMax);
}
else
...{
Console.WriteLine("Has no SecMax.");
}
}
}
public class SecMax
... {
//record the second max number
private static int secMax = Int32.MinValue;
//does the list has second max number
private static bool HasSecMax(int[] list)
...{
int max = list[0];
//get the max number
for(int i = 1;i < list.Length;i++)
...{
if(list[i] > max)
...{
max = list[i];
}
}
bool isFound = false;
//get the second max number
for(int j = 0;j < list.Length;j++)
...{
if((list[j] < max) && (list[j] > secMax))
...{
secMax = list[j];
isFound = true;
}
}
return isFound;
}
public static void Main()
...{
int[] list = new int[]...{1,2,3,4,5,6,7};
if(HasSecMax(list))
...{
Console.WriteLine("The SecMax number is:" + secMax);
}
else
...{
Console.WriteLine("Has no SecMax.");
}
}
}