title: Minimum difference in an array
body: <p>I want to find the minimum difference among all elements of an array. I read through various other questions, but couldn't find the exact source of the error in the following code. </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;stdio.h&gt;
  #include&lt;cstdlib&gt;
  
  using namespace std;
  
  void quicksort(long int *lp, long int *rp);
  
  int main()
  {
      int t,n;
      long int s[5000];
  
      cin&gt;&gt;t;
      while(t--){
      cin&gt;&gt;n;
      for(int i=0;i&lt;n;i++) cin&gt;&gt;s[i];
      quicksort(&amp;s[0],&amp;s[n-1]);
      //cout&lt;&lt;"passes:"&lt;&lt;passes&lt;&lt;endl;
      //for(int i=0;i&lt;n;i++) cout&lt;&lt;s[i]&lt;&lt;" ";
      long int min = abs(s[1]-s[0]);
      //cout&lt;&lt;endl&lt;&lt;min;
      for(int i=1;i&lt;(n-1);i++){
          long int temp = abs(s[i]-s[i+1]);
          if (temp &lt;= min) min = temp;
      }
      cout&lt;&lt;min;
      }
  }
  
  void quicksort(long int *lp,long int *rp){
      int arraysize= (rp-lp)+1;
      if(arraysize &gt; 1){
         long int *pivot = (lp+(arraysize/2));
         long int swap=0;
        long int *orgl = lp;
        long int *orgr = rp;
        while(lp!=rp){
          while (*lp &lt; *pivot) lp++;
          while (*rp &gt; *pivot) rp--;
          if (lp == pivot) pivot=rp;
          else if (rp == pivot) pivot=lp;
          swap = *lp;
          *lp = *rp;
          *rp = swap;
          if((*lp == *pivot) || ( *rp == *pivot)) break;
      }
      quicksort(orgl,pivot-1);
      quicksort(pivot+1,orgr);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The problem statement is given in this link : <a href="http://www.codechef.com/problems/HORSES" rel="nofollow">http://www.codechef.com/problems/HORSES</a>
  Can you please identify the error in my program ?</p>