title: Quicksort in C - Just a number not sorted
body: <p>i'm trying to implement a quicksort algorithm, it went well to be honest,except for a single detail, one number is not sorted at the end... then i tried doing it very similar as i saw in a book, still the same (i'm sure it is a very small detail in the code, but i just can't find it)</p>
  
  <p>i'll post it here </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int i,j,x,y;
  
  void qs(int *vect,int start, int end);
  
  int main() {
      int arr[] = {0,4,5,6,9,3,2,1};
      int amount;
      amount= sizeof(arr)/sizeof(arr[0]);
      //print array
      for ( i = 0; i &lt; sizeof(arr)/sizeof(arr[0]); i++) {
          printf("before = [%d]\n",arr[i]);
      }
  
      qs(arr,0,amount-1);
  
      for ( i = 0; i &lt; sizeof(arr)/sizeof(arr[0]); i++) {
          printf("after: [%d]\n",arr[i]);
      }
      return 0;
  
  }
  
  
  
  void qs(int *vect,int start, int end){
  
      i = start;
      j = end;
      x = vect[(start + end)/2];
  
      do {
          while(vect[i] &lt; x &amp;&amp; i &lt; end){
              i++;
          }
  
          while (vect[j] &gt; x &amp;&amp; j &gt; start){
              j--;
          }
  
          if (i&lt;=j) {
              y = vect[i];
              vect[i] = vect[j];
              vect[j] = y;
              i++;
              j--;
          }
      }
      while(i&lt;=j);
  
      if (start&lt;j) {
          qs(vect,start,j);
      }
      else{
          if (i&lt;end) {
              qs(vect,end,i);
          }
      }
      return ;
  }
  </code></pre>
  
  <p>and the result:</p>
  
  <p>before = [0]</p>
  
  <p>before = [4]</p>
  
  <p>before = [5]</p>
  
  <p>before = [6]</p>
  
  <p>before = [9]</p>
  
  <p>before = [3]</p>
  
  <p>before = [2]</p>
  
  <p>before = [1]</p>
  
  <p>__</p>
  
  <p>after: [0]</p>
  
  <p>after: [1]</p>
  
  <p>after: [2]</p>
  
  <p>after: [3]</p>
  
  <p>after: [4]</p>
  
  <p>after: [5]</p>
  
  <p>after: [9]</p>
  
  <p>after: [6] &lt;---------- this little guy </p>