Most efficient way to find the greatest of three ints

前端 未结 14 1230
离开以前
离开以前 2020-12-30 07:58

Below is my pseudo code.

function highest(i, j, k)
{
  if(i > j && i > k)
  {
    return i;
  }
  else         


        
14条回答
  •  离开以前
    2020-12-30 08:32

    To find the greatest you need to look at exactly 3 ints, no more no less. You're looking at 6 with 3 compares. You should be able to do it in 3 and 2 compares.

    int ret = max(i,j);
    ret = max(ret, k);
    return ret;
    

提交回复
热议问题