title: quicksort implementation
body: <p>Following code for quicksort does not work and I can't understand what is reason.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  void exch(int a[],int i,int j){
      int s=a[i];
      a[i]=a[j];
      a[j]=s;
  
  }
  int  partition(int a[],int l,int h);
  void quick(int a[],int l,int h){
      if (h&lt;=l) return ;
      int j=partition(a,l,h);
      quick(a,l,j-1);
      quick(a,j+1,h);
      }
  int partition(int a[],int l,int h){
      int i=l-1;
      int j=h;
      int v=a[l];
      while(true){
  
          while( a[++i]&lt;v);
  
          while(a[--j]&gt;v) if (j==i)  break;
  
              if (i&gt;=j) break;
  
          exch(a,i,j);
  
      }
  
      exch(a,i,h);
      return i;
  
  
  
  }
  int main(){
  
      int a[]={12,43,13,5,8,10,11,9,20,17};
      int n=sizeof(a)/sizeof(int);
  quick(a,0,n-1);
   for (int  i=0;i&lt;n;i++){
       cout&lt;&lt;a[i]&lt;&lt;"  ";
   }
       return 0;
   }
  </code></pre>
  
  <p>It outputs    </p>
  
  <pre><code>5  8  9  11  10  17  12  20  13  43
  </code></pre>