Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct {
- void** values;
- size_t len, capacity;
- } ArrList;
- ArrList* init_list(size_t capacity) {
- ArrList *l = (ArrList*) calloc(1, sizeof(ArrList));
- l->capacity = capacity;
- l->len = 0;
- l->values = (void**) calloc(capacity, sizeof(void*));
- return l;
- }
- void add_value(ArrList *l, void *value) {
- if(l->len == l->capacity) {
- l->capacity += 100;
- l->values = (int*) realloc(l->values, l->capacity *sizeof(void*));
- }
- l->values[l->len++] = value;
- }
- void destroy_arrlist(ArrList *list, void (*destroy_value)(void* value)) {
- for(int i = 0; i < list->len; i++)
- destroy_value(*(list->values + i));
- free(list);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement