title: Function to choose a pivot for quick sort
body: <pre><code>int choose_pivot(int lo, int hi){
     int mid = ((hi-lo)/2)+1;
     if((arr[hi]&lt;arr[lo])^(arr[hi]&lt;arr[mid])){
        return hi;
     }
     else if((arr[lo]&lt;arr[hi])^(arr[lo]&lt;arr[mid])){
        return lo;
     }
     else{
        return mid;
     }
  }
  </code></pre>
  
  <p>This function should  choose the pivot as follows. Consider the first, middle, and final elements of the given array. (If the array has odd length it should be clear what the "middle" element is; for an array with even length 2k, use the kth element as the "middle" element. Identify which of these three elements is the median. Return the its value.</p>
  
  <p>Is there anything wrong with this function which may not let it do what it is meant for? Am I missing some case for which the function doesn't give desired result?</p>