create vector s
Definition
vector_t *create_vector_s(compare_vector_value_t compare_func);
Description
Allocates memory for the vector structure with sorted elements. It isn't sorted just by calling a function like vector_sort(vector). Instead it will find the correct position when a new element is pushed.
Parameters
- compare_func
- Function to compare 2 elements
Return Value
Allocated vector_t structure.
Example
#include <stdio.h> #include <libc/vector.h> signed char compare_double_value(void *ptr1, void *ptr2) { if(*((double *)ptr1) < *((double *)ptr2)) { return VECTOR_COMPARE_LESS; } else if(*((double *)ptr1) == *((double *)ptr2)) { return VECTOR_COMPARE_EQUAL; } else { return VECTOR_COMPARE_MORE; } } int main(int argc, char *argv[]) { // create a vector with double elements sorting vector_t *vector = create_vector_s(compare_double_value); destroy_vector(vector); return 0; }