title: QuickSort code not working
body: <p>I've been trying to learn how to implement quick sort. I read the basic algorithm and tried to implement my own code for it first (based off of my understanding of the algorithm).</p>
  
  <p>For the sake of simplicity, I'm taking the pivot as the first element. Please ignore that if you can. My code runs but does not return the correct result and I'm not able to figure out why. Any help is much appreciated.</p>
  
  <pre><code>public class QuickSortMain 
  {
  public static void displayArray(int[] arr)
  {
      for(int i = 0; i &lt; arr.length; i++)
          System.out.print(arr[i] + "  ");
  }
  
  public static void quickSort(int[] arr)
  {
      quickSort(arr, 0, arr.length - 1);
  }
  
  private static void quickSort(int[] arr, int lo, int hi)
  {
      if(lo &gt;= hi) return;
  
      int j = lo;
      int left = lo;
      int right = hi;
  
      while(arr[left] &lt;= arr[j])
          left++;
  
      while(arr[right] &gt;= arr[j])
          right--;
  
      if (left &gt;= right) return;
  
      swap(arr, left, right);
      swap(arr, j, left);
  
      quickSort(arr, lo, j-1);
      quickSort(arr, j+1, hi);
  }
  
  private static void swap(int[] arr, int i1, int i2)
  {
      int temp = arr[i1];
      arr[i1] = arr[i2];
      arr[i2] = temp;
  }
  
  public static void main(String[] args)
  {
  
      int[] myArray = {14, 79, 11, 42, 3, 27, 192, 44, 26, 742, 129};
      System.out.println(myArray.length);
      System.out.println("Original Array:");
      displayArray(myArray);
  
      quickSort(myArray);
      System.out.println("");
      System.out.println("Sorted Array:");
      displayArray(myArray);
  
  }
  }
  </code></pre>
  
  <p>Here is the output I get:
  11
  Original Array:
  14  79  11  42  3  27  192  44  26  742  129<br>
  Sorted Array:
  3  14  11  42  79  27  192  44  26  742  129  </p>
  
  <p>Thanks!</p>