title: quickselect algorithm
body: <p>when i run  following code for quickselection</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  const int n = 15;
  int b[100];
  int btotal=0;
  int c[100];
  int ctotal=0;
  
  void read(int a[],int size){
      for (int i=1; i&lt;=15; i++) cin &gt;&gt; a[i];
  }
  
  int quickselect(int a[], int k)
  {
      int r = 1 + rand()%(n-1);
      int pivot = a[r];
      for (int i=1; i&lt;=n; i++) {
          if (a[i] &lt; pivot) {
              b[i] = a[i];
              ++btotal;
          }
  
          if (a[i] &gt; pivot) {
              c[i] = a[i];
              ++ctotal;
          }  
      }
  
      if (k &lt;= btotal) quickselect(b,k);
      if (k &gt; (n-ctotal)) return quickselect(c, k - (n-ctotal));        
  
      return pivot;          
  }
  
  int main(int argc, char *argv[])
  {
      int a[n];
      cout &lt;&lt;" enter contents of array " &lt;&lt; endl;
      read(a, n);
      quickselect(a, 6);
      //system("PAUSE");
      //return EXIT_SUCCESS;
      return 0;
  }
  
  1 4 2 3 5 7 6 9 8 10 13 12 11 15 14
  </code></pre>
  
  <p>i have got runtime error,i think here it is problem related with  indexing,but can't find where,please help me</p>