title: Implementation of Quick Sort
body: <pre><code>#include&lt;stdio.h&gt;
  #include&lt;iostream.h&gt;
  #include&lt;conio.h&gt;
  
  void quicks(int *arr,int x,int pivot,int lo,int hi);
  void swap1(int *x,int *y);
  int main()
  {
  int *arr = new int[7];
  arr[0] = 23;
  arr[1] = 3;
  arr[2] = -23;
  arr[3] = 45;
  arr[4] = 12;
  arr[5] = 76;
  arr[6] = -65;
  quicks(arr,7,0,1,6);
  for(int i = 0;i&lt;7;i++)
      std::cout &lt;&lt; arr[i] &lt;&lt;"\t";
  getch();
  return 0;
   }
   void quicks(int *arr,int x,int pivot,int lo,int hi)
   {
  int i = lo,j = hi;
  if(pivot &lt; x-1)
  {
  while(i &lt;= hi)
  {
      if(arr[i] &lt;= arr[pivot])
          i++;
      else
          break;
  }
  while(j &gt;= lo)
  {
      if(arr[j] &gt;= arr[pivot])
          j--;
      else    
          break;
  }
  if( i &gt; j)
  {
      swap1(&amp;arr[j],&amp;arr[pivot]);
      lo = pivot+1;
      hi = x - 1;
      quicks(arr,x,pivot,lo,hi);
  }
  else if(i == j)
  {
      pivot = pivot + 1;
      lo = pivot+1;
      hi = x - 1;
      quicks(arr,x,pivot,lo,hi);
  }
  else if(i &lt; j)
  {
      swap1(&amp;arr[j],&amp;arr[i]);
      lo = i + 1;
      hi = j - 1;
      quicks(arr,x,pivot,lo,hi);
  }
  }
  else
  {
      printf("\nDONE\n");
  }
  }
  
  void swap1(int *x,int *y)
  {
  int temp;
  temp = *x;
  *x = *y;
  *y = temp;
  }
  </code></pre>
  
  <p>Hi,
  I have written a program to implement Quick sort.But the program is going into an infinite loop.In the Quicks function,the while loops for incrementing and decrementing i and j are the problem.Can anybody tell me what is wrong with this Implementation of QUick Sort.</p>