0
这里是我的代码:快速排序不排序我的数组
#include <stdio.h>
#include <stdlib.h>
float comp (const void * elem1, const void * elem2) {
float f = *((float*)elem1);
float s = *((float*)elem2);
if (f > s) return 1;
if (f < s) return -1;
return 0;
}
int main(void) {
int t, n, temp, temp1, x;
float input[2][50][1000];
scanf("%d", &t);
for(temp=0; temp<t; temp++){
scanf("%d ", &n);
for(temp1=0; temp1<n; temp1++){
scanf("%f", &input[0][temp][temp1]);
}
for(temp1=0; temp1<n; temp1++){
scanf("%f", &input[1][temp][temp1]);
}
for(x=0; x<temp1; x++){
printf("%f", input[0][temp][x]);
}
qsort (input[0][temp], n, sizeof(*input[0][temp]), comp);
printf("\n Sorted Array:");
for(x=0; x<temp1; x++){
printf("%f", input[0][temp][x]);
}
}
return 0;
}
,这里是我的输出: 0.7000000.2000000.800000 有序数组:0.7000000.2000000.800000
谁能告诉为什么的qsort()不为我工作?
比较函数必须返回'int'(而不是'float') –
[**请参阅live **](http://ideone.com/XCDxl0) – WhozCraig
@AlterMann Hail!谢谢 –