java - Fastest way of finding the middle value of a triple? -


Looking at

there is an array of three numeric values ​​and I want to know the value between the three.

The question is the fastest way to find the middle of all ?

My approach is such a pattern - as there are three numbers, there are six permutations:

  if (array [random index]> gt ; = Array [randomIndexB] & amp; array [randomIndexB]> = array [randomIndexC])  

It would be really good if someone sent me more elegant < / I> and fast can help me find a way to do this. / P>

If you are looking for the most efficient solution, I think that's something like this:

  if (array [random index]> array [random index]) {if (array [randomIndexB]> array [randomIndexC]) {return "b is middle value"; } And if (array [random index]> array [random indexx]) {return "C is middle value"; } And {return "is a moderate value"; }} And {if (array [random index]> array [random indexx]) {return "is a middle value"; } And if (array [random index]> array [random indexx]) {return "C is middle value"; } Other {return "B is moderate value"; }}  

This approach requires at least two and maximum of three comparisons. It deliberately ignores the possibility of equality of two values ​​(as your question was): If it is important, then it can also be expanded to check.


Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -