浮点排序
#include <stdlib.h>
#include <stdio.h>
int cmp_float(const void* e1, const void* e2)
{
return *(float*)e1 - *(float*)e2;
}
void test2()
{
float f[] = { 9.0,8.0,7.0,6.0,5.0,4.0};
int sz = sizeof(f) / sizeof(f[0]);
qsort(f, sz, sizeof(f[0]), cmp_float);
int j = 0;
for (j = 0; j < sz; j++)
{
printf("%f ", f[j]);
}
}
int main()
{
test2();
return 0;
}
浮点排序
#include<stdio.h>
#include<stdlib.h>
cmp_int(const void* e1, const void* e2)
{
return *(int*)e1 - *(int*)e2;
}
void test1()
{
int arr[10] = { 9,8,7,6,5,4,3,2,1,0 };
int sz = sizeof(arr) / sizeof(arr[0]);
qsort(arr, sz, sizeof(arr[0]), cmp_int);
int i = 0;
for (i = 0; i < sz; i++)
{
printf("%d", arr[i]);
}
}
int main()
{
test1();
return 0;
}
结果