title: C Array Partition
body: <p>I am trying to use a quicksort on an array, however I'm not entirely sure what I am doing wrong.  My numbers in order should be </p>
  
  <blockquote>
    <p>-2 0 1 4 7 9 11 12 15</p>
  </blockquote>
  
  <p>However I am getting:</p>
  
  <blockquote>
    <p>0 1 4 7 15 12 11 9 -2</p>
  </blockquote>
  
  <p>Here is my partition code:</p>
  
  <pre><code>int partition( int* a, int left, int right)
  {
      int pivot, leftPoint, rightPoint, temp;
      pivot = a[left];
      leftPoint = left;
      rightPoint = right + 1;
  
      while(rightPoint &gt; leftPoint)
      {
          while(a[leftPoint] &lt;= pivot &amp;&amp; leftPoint &lt;= right)
              leftPoint ++;
          while(a[rightPoint] &gt; pivot)
              rightPoint --;
          temp = a[leftPoint]; 
          a[leftPoint] = a[rightPoint]; 
          a[rightPoint] = temp;
      }
      temp = a[left];
      a[left] = a[rightPoint];
      a[rightPoint] = temp;
      return rightPoint;
  }
  </code></pre>
  
  <p>Could someone help explain what is wrong with my algorithm here?</p>
  
  <p>EDIT:
  This is my initial array:</p>
  
  <blockquote>
    <p>7 12 1 -2 0 15 4 11 9</p>
  </blockquote>
  
  <p>I call quicksort as</p>
  
  <pre><code>quicksort(a, 0, 8);
  </code></pre>
  
  <p>This is the implementation of my quicksort:</p>
  
  <pre><code>void quickSort( int a[], int low, int high)
  {
     int pivotPoint;
     if(low &lt; high)
     {
         // divide and conquer
          pivotPoint = partition( a, low, high);
          quickSort( a, low, pivotPoint);
          quickSort( a, pivotPoint + 1, high);
     }
  }
  </code></pre>