title: How can I sort this using pivot as the leftmost key?
body: <p>How can I sort this using pivot as the leftmost key in quick sort? I'm getting the answer incorrectly.</p>
  
  <pre><code>public class QuicksortApp {
      private static int []a = {10, 12, 9, 23, 45, 31, 67, 44, 32, 77};
  
      public static void main(String[] args) {
  
          int left = 0;
          int right = a.length - 1;       
  
          // prints the given array
          printArray();
  
          quickSort(left, right);
  
          System.out.println("");
  
          //prints the sorted array
          printArray();
  
      }
  
      private static void quickSort(int left, int right) {
  
          // If both cursor scanned the complete array quicksort exits
          if(left &gt;= right)
              return;
  
          // We took the right most item of the array as a pivot 
          int pivot = a[right];
          int partition = partition(left, right, pivot);
  
          quickSort(0, partition - 1);
          quickSort(partition + 1, right);
      }
  
      private static int partition(int left, int right, int pivot) {
          int leftCursor = left - 1;
          int rightCursor = right;
  
          while(leftCursor &lt; rightCursor){
                  while(a[++leftCursor] &lt; pivot);
                  while(rightCursor &gt; 0 &amp;&amp; a[--rightCursor] &gt; pivot);
              if(leftCursor &gt;= rightCursor) {
                  break;
              } else {
                  swap(leftCursor, rightCursor);
              }
          }
          swap(leftCursor, right);
          return leftCursor;
      }
  
      public static void swap(int left, int right) {
          int temp = a[left];
          a[left] = a[right];
          a[right] = temp;
      }
  
      public static void printArray() {
          for(int i : a){
              System.out.print(i + " ");
          }
      }       
  }
  </code></pre>