getting wrong output while sorting in C++
<p>The following C++ code sorts an array in descending order using qsort:</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;cstdio&gt;
#include &lt;stdlib.h&gt;
using namespace std;

struct player {
  double data;
  int index;
};

struct player A[] = {{0.690277,0}, {0.517857,1}, {0.780762,2}, {0.0416667,3}, {0.0416667,4}};

int compare (const void * a, const void * b)
{
   return ( ((struct player*)b)-&gt;data - ((struct player*)a)-&gt;data );
}

int main ()
{
  int n;
  qsort (A, 5, sizeof(struct player), compare);
  for (n=0; n&lt;5; n++)
  printf ("data=%lf, index=%d\n", A[n].data, A[n].index);
  return 0;
}
</code></pre>

<p>But I am getting output like this:</p>

<pre><code>data=0.517857, index=1
data=0.780762, index=2
data=0.041667, index=3
data=0.041667, index=4
data=0.690277, index=0
</code></pre>

<p>Is there anything wrong in the code?</p>