public class IntSequence {
private int[] sequence;
public IntSequence(params int[] elements){
sequence = new int[elements.Length];
for(int i = 0; i < elements.Length; i++){
sequence[i] = elements[i];
}
}
public int? Min(){
int theMinimum;
if (sequence.Length == 0)
return null;
else {
theMinimum = sequence[0];
foreach(int e in sequence)
if (e < theMinimum)
theMinimum = e;
}
return theMinimum;
}
public int? Max(){
int theMaximum;
if (sequence.Length == 0)
return null;
else {
theMaximum = sequence[0];
foreach(int e in sequence)
if (e > theMaximum)
theMaximum = e;
}
return theMaximum;
}
// Other useful sequence methods
} |