You should use generic sequence with pointer variable:
struct generic_sequence *s;
Creating the sequence and initializing it with gs_new
:
s = gs_new(3, sizeof(float));
Now you can set
/get
value to
/from
it. Just like normal arrays:
gs_set(s, 1, &float_val);
gs_get(s, 1, &float_val);
Or you can use it as a stack:
gs_push(s, &float_val);
gs_pop(s, &float_val);
You can set a comparing function for it:
int float_cmp(float *left, float *right) {
return *left - *right;
}
gs_set_cmp_fn(s, (generic_sequence_cmp_fn)float_cmp);
Then you can sort it with:
gs_sort(s);
You should free the data when you don't need it.
gs_free(s);
gcc src/*.c && ./a.out