It is odd because it misuses the ternary conditional operator .
Jhshukla's code is better.
If you are interested in minimizing the number of comparisons, which is
pretty common for this operation, then you want to do both min and max
finding at one time. Only 3 comparisons are needed.
void swap_if_out_of_order(int& x, int& y)
{
if (x > y) { int t = x; x = y; y = t; }
}
void find_min_and_max(int x, int y, int z, int& min, int& max)
{
// bubble the min down to x
swap_if_out_of_order(y, z);
swap_if_out_of_order(x, y);
// now bubble the max up to z
swap_if_out_of_order(y, z);
// set return values
min = x;
max = z;
}
A compiler that does a good job of inlining small functions will
generate very good code from this source, yet it is fairly readable.