title: Will this modified partitioning algorithm in quicksort function the same as the original in all situations?
body: <p>The code given in class for QuickSort partitioning procedure had two inner loops with an
  empty body. Suppose we rewrite these loops by moving the increment/decrement from the
  test into the body of the loop, and by modifying the initial values of the indexes accordingly.
  The original and modified partitioning procedures are as follows:</p>
  
  <pre><code>int partition( A[], int l, int r )
  {
      int pivot = A[l];
      int i = l, j = r+1;
  
      while(i &lt; j)
      {
          while (A[--j] &gt; pivot);
          while (A[++i] &lt; pivot);
          if (i &lt; j) swap (A[i], A[j]);
      }
      swap(A[l], A[j]);
      return j;
  }
  
  int partition( A[], int l, int r )
  {
      int pivot = A[l];
      int i = l+1, j = r;
  
      while (i &lt; j)
      {
           while (A[j] &gt; pivot) j--;
           while (A[i] &lt; pivot) i++;
           if (i &lt; j) swap(A[i], A[j]);
      }
      swap(A[l], A[j])
      return j;
  }
  </code></pre>
  
  <p>Does the modified partitioning procedure work correctly in all situations? (ignore the
  glitch of i running off the array when the pivot is the maximal element). Hint: consider what
  happens when the current subarray contains at least two other keys equal to the pivot.</p>