You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
743 B
30 lines
743 B
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// https://aticleworld.com/implement-vector-in-c/
|
|
|
|
#define VECTOR_INIT_CAPACITY 6
|
|
#define UNDEFINE -1
|
|
#define SUCCESS 0
|
|
//Store and track the stored data
|
|
typedef struct sVectorList
|
|
{
|
|
void **items;
|
|
int capacity;
|
|
int total;
|
|
} sVectorList;
|
|
//structure contain the function pointer
|
|
typedef struct sVector vector;
|
|
struct sVector
|
|
{
|
|
sVectorList vectorList;
|
|
//function pointers
|
|
int (*pfVectorTotal)(vector *);
|
|
int (*pfVectorResize)(vector *, int);
|
|
int (*pfVectorAdd)(vector *, void *);
|
|
int (*pfVectorSet)(vector *, int, void *);
|
|
void *(*pfVectorGet)(vector *, int);
|
|
int (*pfVectorDelete)(vector *, int);
|
|
int (*pfVectorFree)(vector *);
|
|
};
|
|
void vector_init(vector *v); |