Fastest way of finding the middle value of a triple?

前端 未结 25 958
庸人自扰
庸人自扰 2020-12-04 12:20

Given is an array of three numeric values and I\'d like to know the middle value of the three.

The question is, what is the fastest way of finding the midd

25条回答
  •  青春惊慌失措
    2020-12-04 12:45

    And one more idea. There are three numbers {a,b,c}. Then:

    middle = (a + b + c) - min(a,b,c) - max(a,b,c);
    

    Of course, we have to remember about numeric limits...

提交回复
热议问题