How about qsort?
Code:
#include <stdio.h>
#include <stdlib.h>
int fcmp(const void* a, const void *b)
{
const float *x = a;
const float *y = b;
if(*x > *y)
{
return 1;
}
if(*x < *y)
{
return -1;
}
return 0;
}
void show(const float *value, size_t size)
{
while(size--)
{
printf("%14.6f\n", *value++);
}
}
int main(void)
{
float array[] = { 1.23F, 0.0F, -15.6F, 23.45, -1.0F, 1.23456F, 5.16F };
puts("BEFORE");
show(array,sizeof(array)/sizeof(*array));
qsort(array,sizeof(array)/sizeof(*array),sizeof(*array),fcmp);
puts("AFTER");
show(array,sizeof(array)/sizeof(*array));
return 0;
}
/* my output
BEFORE
1.230000
0.000000
-15.600000
23.450001
-1.000000
1.234560
5.160000
AFTER
-15.600000
-1.000000
0.000000
1.230000
1.234560
5.160000
23.450001
*/