新手求教一个简单问题:用qsort函数怎么为float数据排序?
#include<stdio.h> #include<stdlib.h>
int commp(const void *a, const void *b)
{
return ((int *)a)[0] - ((int *)b)[0];
}
main()
{
int i,a[5][2] = {2,0, 3,3, 4,5, 1,1, 99,22};
qsort(a, sizeof(a)/sizeof(int)/2, 2*sizeof(int ),commp);
for(i = 0; i < sizeof(a)/sizeof(int )/2; i++)
{
if(a[i][1] != 0)
{
printf("%d", a[i][0]);
printf("\n");
break;
}
}
return 0;
}
1
Press any key to continue
怎么为float数据排序计算?例如:a[5][2] = {2.01,0, 3.1,-3.2, 4,5, 1,1, 9.9,22};