title: How to write a quicksort partition function
body: <p>This is driving me crazy, I know it's some one-off error causing this, but for some reason, my partition function isn't partitioning correctly. What am I doing wrong?</p>
  
  <pre><code>public static int partition(int numbers[], int lhs, int rhs) {
      int pivot = numbers[(rhs - lhs) / 2];
      int lIndex = lhs - 1;
      int rIndex = rhs + 1;
  
      while (true) {
          while (numbers[++lIndex] &lt; pivot);
          while (numbers[--rIndex] &gt; pivot);
  
          if (lIndex &gt; rIndex) break;
  
          int temp = numbers[lIndex];
          numbers[lIndex] = numbers[rIndex];
          numbers[rIndex] = temp;
      }
  
      return lIndex;
  }
  </code></pre>