I've seen this before. (hehe)
Key here is Math class. Math.Min or Math.Max takes only two argument, but can be expanded to work for more than that, indefinitely.
Here's an example with 3 variables. int var1, var2, var3;
int max = Math.max(var1, Math.max(var2, var3)); int min = Math.min(var2, Math.max(var2, var3)); int middle = var1 + var2 + var3 - max - min I can do this with even more than 3, but it gets a little messy. Here's a helpful visual on imgur. Direct Album
By now you know howI'll shorten Math.Max to use Math.Maxmax() and Math.Min with more than one argumentMath. From now onmin() to min, I'll use python style max() and min() that accepts variable amount of arguments.
egfrom here. max(1, 2, 3) same as Math.Max(1, Math.Max(2, 3))
// a, b, c, d = int max1 = max(a, b) max2 = max(c, d) min1 = min(a, b) min2 = min(c, d) max = max(max1, max2) mid_high = max(min1, min2) mid_low = min(max1, max2) min = min(min1, min2) This works with 3 arguments too.
max1 = max(a, b) max2 = max(b, c) // or a, c : doesn't matter, as long as you have all three argument min1 = min(a, b) min2 = min(b, c) // or a, c : doesn't matter, as long as you have all three argument mid = min(max1, max2) mid = max(min1, min2) I hope you learned a new technique today