I created a generic vector:
typedef struct vector_t
{
int max; /* max number of elements */
int size; /* number of elements present into the array */
void **data; /* array of elements */
};
I’d like to know if in standard Ansi-C exists a function for searching a specific element if the array is not sorted. (I know bsearch if the array is sorted).
I have to create my own function?
Thanks.
If your data isn’t sorted, then “searching” would be just be a for loop that goes through the elements and compares with the search value. If you’re going to be searching often, then you should probably sort your data. There are standard functions for doing the sorting, like qsort()