Fastest way of finding the middle value of a triple?

前端 未结 25 939
庸人自扰
庸人自扰 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 13:02

    It can be solved in one line by the ternary operator

    int middle(int A, int B, int C) {
          return (A>B&&A>C)?B>C?B:C:(B>C&&B>A)?A>C?A:C:B;
    }
    

提交回复
热议问题