title: C++: Sorting 2D array one based of 1 row
body: <p>I have a 2D array with 2 rows and it has very large numbers (upto 10^9) in it.
  I am trying to sort the array based on <em>0th</em> row.</p>
  
  <p>Eg : I have an array : <code>A[5][2]={{1,0},{3,1},{2,2},{6,3},{5,4}}</code> where 2nd row is index of the element.</p>
  
  <p>Now I want to sort the array with retaining the original index.  </p>
  
  <p>After sorting A should be:</p>
  
  <pre><code> A[5][2]={{1,0},{2,2},{3,1},{5,4},{6,3}}
  </code></pre>
  
  <p>I did the following :</p>
  
  <pre><code>long long a[n+1][2];
  
      for (long long i = 0; i &lt; n; i++) 
      {
          cin&gt;&gt;a[i][0];
          a[i][1]=i;
      }
  
  
  
      qsort(a, n, sizeof a[0], compare);
  </code></pre>
  
  <p>And the compare function is :</p>
  
  <pre><code>int compare ( const void *pa,const void *pb )
  {
      int *a = (int*)pa;
      int *b = (int*)pb;
      if(a[0] == b[0])
          return a[1] - b[1];
      else
          return a[0] - b[0];
  }
  </code></pre>
  
  <p>It is working for small values of numbers. For large values,I am getting runtime error (SIGSEGV). </p>
  
  <p>Can someone help in correcting the error ? Or is there a more efficient way to do this ?</p>
  
  <p><strong><em>Note</em></strong> : I had tried long long in compare function but it was giving conversion error.<br>
  <code>error: invalid conversion from 'll (*)(const void*, const void*) {aka long long int (*)(const void*, const void*)}' to '__compar_fn_t {aka int (*)(const void*, const void*)}' [-fpermissive]</code></p>
  
  <p><strong><em>EDIT</em></strong> : Actually I could work away with only the index after sorting.</p>