Fastest way of finding the middle value of a triple?

前端 未结 25 961
庸人自扰
庸人自扰 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:03

        if(array[aIndex] > array[bIndex]) {
            if(array[bIndex] > array[cIndex]) return bIndex;
            if(array[aIndex] > array[cIndex]) return cIndex;
            return aIndex;
        } else {
            if(array[bIndex] < array[cIndex]) return bIndex;
            if(array[aIndex] < array[cIndex]) return cIndex;
            return aIndex;
        }
    

提交回复
热议问题