title: Why the Median-Three-Partition in QuickSort will hide the pivot before returning the pivot value?
body: <p>I was confused by this median3 function in quick sort (it comes from Mark Allen Weiss's <em>Data Structures and Algorithm Analysis in C</em>):</p>
  
  <pre><code>ElementType
  Median3(ElementType A[], int Left, int Right){
      int Center = (Left + Right)/2;
  
      if(A[Left] &gt; A[Center]{
          Swap(&amp;A[Left], &amp;A[Center]);
      }
      if(A[Left] &gt; A[Right]{
          Swap(&amp;A[Left], &amp;A[Right]);
      }
      if(A[Center] &gt; A[Right]{
          Swap(&amp;A[Center], &amp;A[Right]);
      }
  
      Swap( &amp;A[Center], &amp;A[Right - 1]);  /* Hide pivot */
      return A[right - 1];
  }
  </code></pre>
  
  <p>Why does this function hide the pivot before it return the pivot value?</p>
  
  <p>My thinking is that it want to reduce the impact of the pivot in recursive quick sort. Because each time Quick Sort do a recursive calls to itself with left/right part, the center element will be the edge. </p>
  
  <p>Is that right? Hope someone could help me. Thx~!</p>