double min(const double a, const double b) { if (a > b) return b; return a; } double max(const double a, const double b) { if (a > b) return a; return b; } double min(const double a, const double b, const double c) { if ((b < a) && (c < a)) return min(b, c); // a is the greatest if ((a < b) && (c < b)) return min(a, c); // b is the greatest /*if ((a < c) && (b < c))*/ return min(a, b); // c is the greatest } double max(const double a, const double b, const double c) { if ((b > a) && (c > a)) return max(b, c); // a is the smallest if ((a > b) && (c > b)) return max(a, c); // b is the smallest /*if ((a > c) && (b > c))*/ return max(a, b); // c is the smallest } double SecondMin(const double a, const double b, const double c, const double d) { if ((b > a) && (c > a) && (d > a)) return min(b, c, d); // a is smallest if ((a > b) && (c > b) && (d > b)) return min(a, c, d); // b is smallest if ((a > c) && (b > c) && (d > c)) return min(a, b, d); // c is smallest /*if ((a > d) && (b > d) && (c > d))*/ return min(a, b, c); // d is smallest } double SecondMax(const double a, const double b, const double c, const double d) { if ((b < a) && (c < a) && (d < a)) return max(b, c, d); // a is greatest if ((a < b) && (c < b) && (d < b)) return max(a, c, d); // b is greatest if ((a < c) && (b < c) && (d < c)) return max(a, b, d); // c is greatest /*if ((a < d) && (b < d) && (c < d))*/ return max(a, b, c); // d is greatest }