title: Number of comparisons made in median of 3 function?
body: <p>As of right now, my functioin finds the median of 3 numbers and sorts them, but it always makes three comparisons. I'm thinking I can use a nested if statement somewhere so that sometimes my function will only make two comparisons. </p>
  
  <pre><code>int median_of_3(int list[], int p, int r)
  {
      int median = (p + r) / 2;
  
      if(list[p] &gt; list[r])
          exchange(list, p, r);
      if(list[p] &gt; list[median])
          exchange(list, p, median);
      if(list[r] &gt; list[median])
          exchange(list, r, median);
  
      comparisons+=3;                // 3 comparisons for each call to median_of_3
  
      return list[r];
  }
  </code></pre>
  
  <p>I'm not sure I see where I can make that nested if statement. </p>